Changeset 12710


Ignore:
Timestamp:
May 3, 2019 9:17:36 AM (8 months ago)
Author:
tgutzmann
Message:

#5764 Fixed coding conventions, cleaned up exception handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/util/QualifiedName.java

    r12706 r12710  
    117117
    118118        try {
    119            if (ms.nextToken().getId() != ID_TOKEN_VALUE)
     119           if (ms.nextToken().getId() != ID_TOKEN_VALUE) {
    120120               return false;
    121            if (ms.nextToken().getId() != EOF_TOKEN_VALUE)
     121           }
     122           if (ms.nextToken().getId() != EOF_TOKEN_VALUE) {
    122123               return false;
     124           }
    123125           return true;
    124126        } catch (IOException e) {
    125127            // This shouldn't happen when using a StringReader.
    126             throw new RuntimeException("Unhandled internal error", e);
     128            throw nameFormatException(name);
    127129        } catch (Exception e) {
    128130            // Scanner cannot handle this, so this is not a valid identifier.
     
    138140    public boolean isGlobal() {
    139141        return isGlobal;
     142    }
     143   
     144    private static NameFormatException nameFormatException(String name) {
     145        return new NameFormatException(name + " is not a valid qualified name");
    140146    }
    141147
     
    157163            do {
    158164                sym = ms.nextToken();
    159                 if (sym.getId() != ID_TOKEN_VALUE)
    160                     throw new NameFormatException("The qualified name is not valid");
     165                if (sym.getId() != ID_TOKEN_VALUE) {
     166                    throw nameFormatException(name);
     167                }
    161168                names.add((String)sym.value);
    162169            } while ((sym = ms.nextToken()).getId() == DOT_TOKEN_VALUE);
    163             if (sym.getId() != EOF_TOKEN_VALUE)
    164                 throw new NameFormatException("Invalid name: " + name);
    165         } catch (IOException e) {
    166             // This shouldn't happen when using a StringReader.
    167             throw new RuntimeException("Unhandled internal error", e);
    168         } catch (Exception e) {
    169             // Identifier not valid.
    170             throw new NameFormatException("Invalid name: " + name);
     170            if (sym.getId() != EOF_TOKEN_VALUE) {
     171                throw nameFormatException(name);
     172            }
     173        } catch (Exception | IOException e) {
     174            // beaver.Scanner.Exception means invalid name, whereas IOException should never happen with a StringReader.
     175            throw nameFormatException(name);
    171176        }
    172177    }
Note: See TracChangeset for help on using the changeset viewer.