001/*
002 * Copyright (c) 2012-2018 Institut National des Sciences Appliquées de Lyon (INSA Lyon) and others
003 *
004 * This program and the accompanying materials are made available under the
005 * terms of the Eclipse Public License 2.0 which is available at
006 * http://www.eclipse.org/legal/epl-2.0.
007 *
008 * SPDX-License-Identifier: EPL-2.0
009 */
010
011package gololang.ir;
012
013import java.util.HashMap;
014
015public enum OperatorType {
016
017  PLUS("+"),
018  MINUS("-"),
019  TIMES("*"),
020  DIVIDE("/"),
021  MODULO("%"),
022
023  EQUALS("=="),
024  NOTEQUALS("!="),
025  LESS("<"),
026  LESSOREQUALS("<="),
027  MORE(">"),
028  MOREOREQUALS(">="),
029
030  AND("and"),
031  OR("or"),
032  NOT("not"),
033
034  IS("is"),
035  ISNT("isnt"),
036
037  OFTYPE("oftype"),
038
039  ORIFNULL("orIfNull"),
040
041  ANON_CALL(""),
042  METHOD_CALL(":"),
043  ELVIS_METHOD_CALL("?:");
044
045  private final String symbol;
046
047  private static final HashMap<String, OperatorType> SYMBOL_MAPPING = new HashMap<>();
048  static {
049    for (OperatorType op : values()) {
050      SYMBOL_MAPPING.put(op.toString(), op);
051    }
052  }
053
054  OperatorType(String symbol) {
055    this.symbol = symbol;
056  }
057
058  @Override
059  public String toString() {
060    return symbol;
061  }
062
063  public static OperatorType of(Object value) {
064    if (value instanceof OperatorType) {
065      return (OperatorType) value;
066    }
067    if (SYMBOL_MAPPING.containsKey(value)) {
068      return SYMBOL_MAPPING.get(value);
069    }
070    throw new IllegalArgumentException("An operator can't be create from " + value);
071  }
072}