Converts the given String, specified as a static expression
string, to the given expected type.  The conversion is cached.
494436
Object convertStaticValueToExpectedType(String pValue,
                                            Class pExpectedType,
                                            Logger pLogger)
            throws ELException {
        // See if the value is already of the expected type
        if (pExpectedType == String.class ||
                pExpectedType == Object.class) {
            return pValue;
        }

        // Find the cached value
        Map valueByString = getOrCreateExpectedTypeMap(pExpectedType);
        if (!mBypassCache &&
                valueByString.containsKey(pValue)) {
            return valueByString.get(pValue);
        } else {
            // Convert from a String
            Object ret = Coercions.coerce(pValue, pExpectedType, pLogger);
            valueByString.put(pValue, ret);
            return ret;
        }
    }
171059
public static AbstractType<?> parse(String str) throws SyntaxException, ConfigurationException
    {
        if (str == null)
            return BytesType.instance;

        AbstractType<?> type = cache.get(str);

        if (type != null)
            return type;

        // This could be simplier (i.e. new TypeParser(str).parse()) but we avoid creating a TypeParser object if not really necessary.
        int i = 0;
        i = skipBlank(str, i);
        int j = i;
        while (!isEOS(str, i) && isIdentifierChar(str.charAt(i)))
            ++i;

        if (i == j)
            return BytesType.instance;

        String name = str.substring(j, i);
        i = skipBlank(str, i);

        if (!isEOS(str, i) && str.charAt(i) == '(')
            type = getAbstractType(name, new TypeParser(str, i));
        else
            type = getAbstractType(name);

        // We don't really care about concurrency here. Worst case scenario, we do some parsing unnecessarily
        cache.put(str, type);
        return type;
    }
1155850
@Deprecated
	public static Object convert(final Class<?> clazz, String val)
	{
		return StringToTypeConverter.convert(clazz, val);
	}
1244736
public static ParsedExpression parse(String expression) {
        ParsedExpression pe = (ParsedExpression)PARSED_CACHE.get(expression);

        if(pe != null)
            return pe;

        try {
            NetUIELParser learn = new NetUIELParser(new StringReader(expression));

            ParsedExpression expr = learn.parse();
            expr.seal();

            /* infrequent; this should only happen when there is a cache miss */
            synchronized(PARSED_CACHE) {
                PARSED_CACHE.put(expression, expr);
            }

            return expr;
        } catch(ParseException e) {
            String msg = "Error occurred parsing expression \"" + expression + "\".";
            LOGGER.error(msg, e);
            throw new ExpressionParseException(msg, e);
        } catch(TokenMgrError tm) {
            String msg = "Error occurred parsing expression \"" + expression + "\".";
            LOGGER.error(msg, tm);
            throw new ExpressionParseException(msg, tm);
        }
    }
138676
def type_str(self, short=False):
        
        if short:
            return javabridge.static_call(
                "weka/core/Attribute", "typeToStringShort", "(Lweka/core/Attribute;)Ljava/lang/String;",
                self.jobject)
        else:
            return javabridge.static_call(
                "weka/core/Attribute", "typeToString", "(Lweka/core/Attribute;)Ljava/lang/String;",
                self.jobject)
534469
private Expression createOfType(Expression target, String functionName, @NotNull cqlParser.FunctionContext ctx) {
        AliasedQuerySource source = enterQueryContext(target);
        try {
            checkArgumentCount(ctx, functionName, 1);
            Expression typeArgument = (Expression)visitor.visit(ctx.paramList().expression(0));
            if (!(typeArgument instanceof Literal)) {
                throw new IllegalArgumentException("Expected literal argument");
            }

            Literal typeLiteral = (Literal)typeArgument;
            if (!(DataTypes.equal(typeLiteral.getResultType(), builder.resolveTypeName("System", "String")))) {
                throw new IllegalArgumentException("Expected string literal argument");
            }

            String typeSpecifier = ((Literal)typeArgument).getValue();
            DataType isType = builder.resolveTypeSpecifier(typeSpecifier);

            AliasRef thisRef = of.createAliasRef().withName(source.getAlias());
            boolean isSingular = !(source.getResultType() instanceof ListType);
            DataType elementType = isSingular ? source.getResultType() : ((ListType)source.getResultType()).getElementType();
            thisRef.setResultType(elementType);

            Is is = of.createIs().withOperand(thisRef);
            if (isType instanceof NamedType) {
                is.setIsType(builder.dataTypeToQName(isType));
            }
            else {
                is.setIsTypeSpecifier(builder.dataTypeToTypeSpecifier(isType));
            }
            is.setResultType(builder.resolveTypeName("System", "Boolean"));

            return createQuery(source, null, is, null);
        }
        finally {
            exitQueryContext();
        }
    }
1229161
private Description checkToString(ExpressionTree tree, VisitorState state) {
    Symbol sym = ASTHelpers.getSymbol(tree);
    if (!(sym instanceof VarSymbol || sym instanceof MethodSymbol)) {
      return NO_MATCH;
    }
    Type type = ASTHelpers.getType(tree);
    if (type instanceof MethodType) {
      type = type.getReturnType();
    }
    Tree parent = state.getPath().getParentPath().getLeaf();
    ToStringKind toStringKind = isToString(parent, tree, state);
    if (toStringKind == ToStringKind.NONE) {
      return NO_MATCH;
    }
    if (!typePredicate().apply(type, state)) {
      return NO_MATCH;
    }
    Optional<Fix> fix;
    switch (toStringKind) {
      case IMPLICIT:
        fix = implicitToStringFix(tree, state);
        break;
      case EXPLICIT:
        fix = toStringFix(parent, tree, state);
        break;
      default:
        throw new AssertionError(toStringKind);
    }
    return maybeFix(tree, state, type, fix);
  }
770902
static Class<? extends Matcher<? super ExpressionTree>> getValue(Matches matches) {
    String name;
    try {
      matches.value();
      throw new RuntimeException("unreachable");
    } catch (MirroredTypeException e) {
      DeclaredType type = (DeclaredType) e.getTypeMirror();
      name = ((TypeElement) type.asElement()).getQualifiedName().toString();
    }
    try {
      return asSubclass(Class.forName(name), new TypeToken<Matcher<? super ExpressionTree>>() {});
    } catch (ClassNotFoundException | ClassCastException e) {
      throw new RuntimeException(e);
    }
  }
1181660
@Pure
	protected XExpression fromString(String expression) {
		if (!Strings.isEmpty(expression)) {
			ResourceSet resourceSet = this.context.eResource().getResourceSet();
			URI uri = computeUnusedUri(resourceSet);
			Resource resource = getResourceFactory().createResource(uri);
			resourceSet.getResources().add(resource);
			try (StringInputStream is = new StringInputStream(generateExpressionCode(expression))) {
				resource.load(is, null);
				SarlScript script = resource.getContents().isEmpty() ? null : (SarlScript) resource.getContents().get(0);
				SarlEvent topElement = (SarlEvent) script.getXtendTypes().get(0);
				SarlField member = (SarlField) topElement.getMembers().get(0);
				return member.getInitialValue();
			} catch (Throwable exception) {
				throw new RuntimeException(exception);
			} finally {
				resourceSet.getResources().remove(resource);
			}
		}
		throw new IllegalArgumentException("not a valid expression");
	}
277274
@Override
    public T convertFromString(Class<? extends T> cls, String str) {
        try {
            return fromString.newInstance(str);
        } catch (IllegalAccessException ex) {
            throw new IllegalStateException("Constructor is not accessible: " + fromString);
        } catch (InstantiationException ex) {
            throw new IllegalStateException("Constructor is not valid: " + fromString);
        } catch (InvocationTargetException ex) {
            if (ex.getCause() instanceof RuntimeException) {
                throw (RuntimeException) ex.getCause();
            }
            throw new RuntimeException(ex.getMessage(), ex.getCause());
        }
    }
399390
def from_string(value):
        
        if value == None or len(value) == 0:
            return None
                
        tokens = value.split(",")
        if len(tokens) == 1:
            return TypeDescriptor(tokens[0].strip(), None)
        elif len(tokens) == 2:
            return TypeDescriptor(tokens[0].strip(), tokens[1].strip())
        else:
            raise ConfigException(
                None, "BAD_DESCRIPTOR", "Type descriptor " + value + " is in wrong format"
            ).with_details("descriptor", value)
1219005
public static ValueExpression createValueExpression(PageContext pageContext, String expression, Class<?> expectedType) {
        ExpressionFactory factory = getExpressionFactory(pageContext);
        return factory.createValueExpression(pageContext.getELContext(), expression, expectedType);
    }
509783
public static Expression createExpression(String expression) {
        try {
            return INSTANCE.ctorExpression.newInstance(expression);
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
657537
@Override
	public <T> T asObject(String string, Class<T> valueType) throws BugError {
		// at this point value type is guaranteed to be char or Character
		if (string.length() > 1) {
			throw new ConverterException("Trying to convert a larger string into a single character.");
		}
		return (T) (Character) string.charAt(0);
	}
1124993
def from_string(type_string):
    '''

    '''
    if type_string == NONE:
        return NONE
    elif type_string == PERIODIC_EC_SHARED:
        return PERIODC_EC_SHARED
    elif type_string == PERIODIC_STATE_SHARED:
        return PERIODIC_STATE_SHARED
    elif type_string == GROUPING:
        return GROUPING
    elif type_string == FSM_EC_SHARED:
        return FSM_EC_SHARED
    elif type_string == FSM_STATE_SHARED:
        return FSM_STATE_SHARED
    else:
        raise InvalidCompositeTypeError(type_string)
392905
private static TYPE toTYPE(String type) {
        if (null == type || type.trim().isEmpty()) {
            return TYPE.OBJECT;
        } else {
            return TYPE.valueOf(type.toUpperCase());
        }
    }
1128476
def _str_to_type(cls, context_class, string):
        

        if string in cls._TYPE_NAMES_BUILTIN:
            return eval(string)

        module_ = sys.modules[context_class.__module__]

        if hasattr(module_, string):
            return getattr(module_, string)

        return cls._str_to_type_from_member_module(module_, string)