Changeset 10079


Ignore:
Timestamp:
Aug 23, 2017 8:04:14 AM (2 years ago)
Author:
Zimon Kuhs
Message:

#5447

  • Moved several string methods to the StringUtil class.
  • Created getter and setter for target platforms in ModelicaCompiler.
Location:
trunk/Compiler
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Compiler/ModelicaCompiler/src/jastadd/ModelicaCompiler.jrag

    r10070 r10079  
    14801480        String platforms = programarguments.get("platform");
    14811481        if (platforms != null) {
    1482             targetPlatforms =  platforms.split(",");
     1482            setTargetPlatforms(platforms.split(","));
    14831483        }
    14841484       
     
    19371937
    19381938    /**
     1939     * Retrieves the target platforms.
     1940     *
     1941     * @return  the target platforms.
     1942     */
     1943    public String[] ModelicaCompiler.getTargetPlatforms() {
     1944        return targetPlatforms;
     1945    }
     1946
     1947    /**
     1948     * Sets the target platforms.
     1949     *
     1950     * @param platforms the platforms to set as compilation targets.
     1951     */
     1952    public void ModelicaCompiler.setTargetPlatforms(String... platforms) {
     1953        this.targetPlatforms = platforms;
     1954    }
     1955
     1956    /**
    19391957     * Sets the directory new temporary files are created in.
    19401958     * The default value is <code>null</code>, and is interpreted as the current working directory.
  • trunk/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/separateProcess/CompilerInstance.java

    r9071 r10079  
    2626
    2727import org.jmodelica.util.logging.IllegalLogStringException;
    28 
     28import org.jmodelica.util.xml.StringUtil;
     29
     30/**
     31 * Class representing a compiler instance to be used when compiling with a separate process.
     32 */
    2933public class CompilerInstance {
    3034
     
    8488
    8589    /**
    86      * TODO
    87      * @param paths
     90     * Sets the class path for this compiler instance.
     91     *
     92     * @param paths the class paths.
    8893     */
    8994    public void setClassPath(String... paths) {
     
    159164        if (logs != null) {
    160165            for (String log : logs) {
    161                 if (log.contains("|stderr"))
    162                     throw new IllegalLogStringException("Piping compiler log to stderr is not allowed while separate process is used.", null);
     166                if (log.contains("|stderr")) {
     167                    throw new IllegalLogStringException("Piping compiler log to stderr is not allowed while " +
     168                            "separate process is used.", null);
     169                }
    163170                this.log.add(log);
    164171            }
     
    235242
    236243    private static String join(String delimiter, String... args) {
    237         if (args == null)
    238             return "";
    239         StringBuilder sb = new StringBuilder();
    240         boolean first = true;
    241         for (String str : args) {
    242             if (!first)
    243                 sb.append(delimiter);
    244             first = false;
    245             sb.append(str);
    246         }
    247         return sb.toString();
     244        return StringUtil.join(delimiter, args);
     245    }
     246
     247    private static String join(String delimiter, Collection<String> args) {
     248        return StringUtil.join(delimiter, args);
     249    }
     250
     251    private static String join(String delimiter, String pairDelimiter, Map<String, String> args) {
     252        return StringUtil.join(delimiter, pairDelimiter, args);
    248253    }
    249254
    250255    private static String joinPath(String... args) {
    251         return join(File.separator, args);
    252     }
    253 
    254     private static String join(String delimiter, Collection<String> args) {
    255         StringBuilder sb = new StringBuilder();
    256         boolean first = true;
    257         for (String str : args) {
    258             if (!first)
    259                 sb.append(delimiter);
    260             first = false;
    261             sb.append(str);
    262         }
    263         return sb.toString();
    264     }
    265 
    266     private static String join(String delimiter, String pairDelimiter, Map<String, String> args) {
    267         StringBuilder sb = new StringBuilder();
    268         boolean first = true;
    269         for (Map.Entry<String, String> pair : args.entrySet()) {
    270             if (!first)
    271                 sb.append(delimiter);
    272             first = false;
    273             sb.append(pair.getKey());
    274             sb.append(pairDelimiter);
    275             sb.append(pair.getValue());
    276         }
    277         return sb.toString();
    278     }
    279 
     256        return StringUtil.joinPath(args);
     257    }
     258
     259    /**
     260     * Enumeration class representing the compiler type.
     261     */
    280262    public enum Compiler {
    281         MODELICA("org.jmodelica.modelica.compiler.ModelicaCompiler"), OPTIMICA("org.jmodelica.optimica.compiler.OptimicaCompiler");
     263        /**
     264         * {@link org.jmodelica.modelica.compiler.ModelicaCompiler ModelicaCompiler}.
     265         */
     266        MODELICA("org.jmodelica.modelica.compiler.ModelicaCompiler"),
     267
     268        /**
     269         * {@link org.jmodelica.optimica.compiler.OptimicaCompiler OptimicaCompiler}.
     270         */
     271        OPTIMICA("org.jmodelica.optimica.compiler.OptimicaCompiler");
    282272
    283273        private final String className;
  • trunk/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/util/xml/StringUtil.java

    r10034 r10079  
    11package org.jmodelica.util.xml;
    22
     3import java.io.File;
    34import java.io.IOException;
    45import java.io.OutputStreamWriter;
     
    67import java.io.StringWriter;
    78import java.io.Writer;
     9import java.util.Collection;
     10import java.util.Map;
    811
    912/**
     
    7578    }
    7679
     80    /**
     81     * Joins together a collection of strings, separating them by a delimiter.
     82     *
     83     * @param delimiter the delimiter.
     84     * @param args      the strings to join.
     85     * @return          all strings in {@code args}, delimited by {@code delimiter}.
     86     */
     87    public static String join(String delimiter, Collection<String> args) {
     88        return join(delimiter, args.toArray(new String[args.size()]));
     89    }
     90
     91    /**
     92     * Joins together a collection of strings, separating them by a delimiter.
     93     *
     94     * @param delimiter the delimiter.
     95     * @param args      the strings to join.
     96     * @return          all strings in {@code args}, delimited by {@code delimiter}.
     97     */
     98    public static String join(String delimiter, String... args) {
     99        StringBuilder sb = new StringBuilder();
     100        boolean first = true;
     101        for (String str : args) {
     102            if (!first)
     103                sb.append(delimiter);
     104            first = false;
     105            sb.append(str);
     106        }
     107        return sb.toString();
     108    }
     109
     110    /**
     111     * Joins together a collection of string pairs, separating pairs by a delimiter, and pair members by
     112     * another delimiter.
     113     *
     114     * @param delimiter     the delimiter to separate pairs.
     115     * @param pairDelimiter the delimiter to separate pair members.
     116     * @param args          the pairs.
     117     * @return              all string pairs in {@code args}, delimited by {@code delimiter} and {@code pairDelimiter}.
     118     */
     119    public static String join(String delimiter, String pairDelimiter, Map<String, String> args) {
     120        StringBuilder sb = new StringBuilder();
     121        boolean first = true;
     122        for (Map.Entry<String, String> pair : args.entrySet()) {
     123            if (!first) {
     124                sb.append(delimiter);
     125            }
     126            first = false;
     127            sb.append(pair.getKey());
     128            sb.append(pairDelimiter);
     129            sb.append(pair.getValue());
     130        }
     131        return sb.toString();
     132    }
     133
     134    /**
     135     * Joins together a collection of strings into a path.
     136     * <p>
     137     * Calls {@link #join(String, String...)} with the first argument as {@link File#separator}.
     138     *
     139     * @param args  the strings to join.
     140     * @return      all strings in {@code args}, delimited by {@link File#separator}.
     141     */
     142    public static String joinPath(String... args) {
     143        return join(File.separator, args);
     144    }
    77145}
Note: See TracChangeset for help on using the changeset viewer.