use of com.google.spanner.v1.Type in project cel-java by projectnessie.
the class TypeErrors method formatFunction.
static void formatFunction(StringBuilder result, Type resultType, List<Type> argTypes, boolean isInstance) {
if (isInstance) {
Type target = argTypes.get(0);
argTypes = argTypes.subList(1, argTypes.size());
formatCheckedType(result, target);
result.append(".");
}
result.append("(");
for (int i = 0; i < argTypes.size(); i++) {
Type arg = argTypes.get(i);
if (i > 0) {
result.append(", ");
}
formatCheckedType(result, arg);
}
result.append(")");
if (resultType != null) {
result.append(" -> ");
formatCheckedType(result, resultType);
}
}
use of com.google.spanner.v1.Type in project cel-java by projectnessie.
the class Types method notReferencedIn.
/**
* notReferencedIn checks whether the type doesn't appear directly or transitively within the
* other type. This is a standard requirement for type unification, commonly referred to as the
* "occurs check".
*/
static boolean notReferencedIn(Mapping m, Type t, Type withinType) {
if (t.equals(withinType)) {
return false;
}
Kind withinKind = kindOf(withinType);
switch(withinKind) {
case kindTypeParam:
Type wtSub = m.find(withinType);
if (wtSub == null) {
return true;
}
return notReferencedIn(m, t, wtSub);
case kindAbstract:
for (Type pt : withinType.getAbstractType().getParameterTypesList()) {
if (!notReferencedIn(m, t, pt)) {
return false;
}
}
return true;
case kindFunction:
FunctionType fn = withinType.getFunction();
List<Type> types = flattenFunctionTypes(fn);
for (Type a : types) {
if (!notReferencedIn(m, t, a)) {
return false;
}
}
return true;
case kindList:
return notReferencedIn(m, t, withinType.getListType().getElemType());
case kindMap:
MapType mt = withinType.getMapType();
return notReferencedIn(m, t, mt.getKeyType()) && notReferencedIn(m, t, mt.getValueType());
case kindWrapper:
return notReferencedIn(m, t, Decls.newPrimitiveType(withinType.getWrapper()));
default:
return true;
}
}
use of com.google.spanner.v1.Type in project osate2 by osate.
the class QualifiedNamedElementImpl method setType.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setType(Type newType) {
Type oldType = type;
type = newType;
if (eNotificationRequired()) {
eNotify(new ENotificationImpl(this, Notification.SET, DeclarativePackage.QUALIFIED_NAMED_ELEMENT__TYPE, oldType, type));
}
}
use of com.google.spanner.v1.Type in project cel-java by projectnessie.
the class CheckerTest method check.
@ParameterizedTest
@MethodSource("checkTestCases")
void check(TestCase tc) {
Assumptions.assumeTrue(tc.disabled == null, tc.disabled);
Source src = newTextSource(tc.i);
ParseResult parsed = Parser.parseAllMacros(src);
assertThat(parsed.getErrors().getErrors()).withFailMessage(parsed.getErrors()::toDisplayString).isEmpty();
TypeRegistry reg = ProtoTypeRegistry.newRegistry(com.google.api.expr.test.v1.proto2.TestAllTypesProto.TestAllTypes.getDefaultInstance(), com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes.getDefaultInstance());
Container cont = Container.newContainer(Container.name(tc.container));
CheckerEnv env = newStandardCheckerEnv(cont, reg);
if (tc.disableStdEnv) {
env = newCheckerEnv(cont, reg);
}
if (tc.homogeneousAggregateLiterals) {
env.enableDynamicAggregateLiterals(false);
}
if (tc.env != null) {
if (tc.env.idents != null) {
for (Decl ident : tc.env.idents) {
env.add(ident);
}
}
if (tc.env.functions != null) {
for (Decl fn : tc.env.functions) {
env.add(fn);
}
}
}
CheckResult checkResult = Checker.Check(parsed, src, env);
if (checkResult.hasErrors()) {
String errorString = checkResult.getErrors().toDisplayString();
if (tc.error != null) {
assertThat(errorString).isEqualTo(tc.error);
} else {
fail(String.format("Unexpected type-check errors: %s", errorString));
}
} else if (tc.error != null) {
assertThat(tc.error).withFailMessage(String.format("Expected error not thrown: %s", tc.error)).isNull();
}
Type actual = checkResult.getCheckedExpr().getTypeMapMap().get(parsed.getExpr().getId());
if (tc.error == null) {
if (actual == null || !actual.equals(tc.type)) {
fail(String.format("Type Error: '%s' vs expected '%s'", actual, tc.type));
}
}
if (tc.r != null) {
String actualStr = print(checkResult.getCheckedExpr().getExpr(), checkResult.getCheckedExpr());
String actualCmp = actualStr.replaceAll("[ \n\t]", "");
String rCmp = tc.r.replaceAll("[ \n\t]", "");
assertThat(actualCmp).isEqualTo(rCmp);
}
}
use of com.google.spanner.v1.Type in project snail by acgist.
the class M3u8Builder method buildM3u8.
/**
* <p>新建M3U8信息</p>
*
* @return {@link M3u8}
*
* @throws NetException 网络异常
*/
private M3u8 buildM3u8() throws NetException {
final M3u8.Type type = this.buildType();
final Cipher cipher = this.buildCipher();
List<String> links;
if (type == Type.M3U8) {
links = this.buildM3u8Links();
} else {
// 获取LABEL_EXTINF标签数据
links = this.buildFileLinks(LABEL_EXTINF);
// 没有LABEL_EXTINF标签数据:获取LABEL_EXT_X_BITRATE标签数据
if (CollectionUtils.isEmpty(links)) {
links = this.buildFileLinks(LABEL_EXT_X_BITRATE);
}
if (CollectionUtils.isEmpty(links)) {
throw new NetException("没有下载文件");
}
}
return new M3u8(type, cipher, links);
}
Aggregations