All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.jangaroo.exml.model.Declaration Maven / Gradle / Ivy

There is a newer version: 4.1.0-alpha-8
Show newest version
package net.jangaroo.exml.model;


import net.jangaroo.utils.AS3Type;
import net.jangaroo.utils.CompilerUtils;

import java.util.regex.Pattern;

public class Declaration extends TypedField {
  private String value;

  public Declaration(String name, String value, String type) {
    super(name, type == null || type.length() == 0 ? guessType(value) : type);
    this.value = value;
  }

  private static String guessType(String value) {
    if (value == null) {
      return "Object";
    }
    AS3Type as3Type = CompilerUtils.guessType(value);
    return as3Type == null ? AS3Type.STRING.toString() : as3Type.toString();
  }

  public String getValue() {
    return value;
  }

  public void setValue(String value) {
    this.value = value;
  }

  public boolean isStandAloneConstant() {
    return value == null || Pattern.matches("true|false|null|undefined|\"([^\"\\\\]|\\\\.)*\"|'([^'\\\\]|\\\\.)*'|NaN|[-+]?[0-9][.0-9eE]*", value);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy