use of org.eclipse.n4js.ts.scoping.builtin.BuiltInTypeScope in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeYieldExpression.
protected Result<TypeRef> applyRuleTypeYieldExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final YieldExpression y) throws RuleFailedException {
// output parameter
TypeRef T = null;
TypeRef t = null;
boolean _isMany = y.isMany();
if (_isMany) {
final Expression yieldValue = y.getExpression();
/* G |- yieldValue : var TypeRef yieldValueTypeRef */
TypeRef yieldValueTypeRef = null;
Result<TypeRef> result = typeInternal(G, _trace_, yieldValue);
checkAssignableTo(result.getFirst(), TypeRef.class);
yieldValueTypeRef = (TypeRef) result.getFirst();
final BuiltInTypeScope scope = RuleEnvironmentExtensions.getPredefinedTypes(G).builtInTypeScope;
boolean _isGenerator = TypeUtils.isGenerator(yieldValueTypeRef, scope);
if (_isGenerator) {
t = this.typeSystemHelper.getGeneratorTReturn(G, yieldValueTypeRef);
} else {
final ParameterizedTypeRef itTypeRef = RuleEnvironmentExtensions.iterableTypeRef(G, TypeUtils.createWildcard());
/* G |- yieldValueTypeRef <: itTypeRef */
boolean _ruleinvocation = subtypeSucceeded(G, _trace_, yieldValueTypeRef, itTypeRef);
final boolean isIterable = _ruleinvocation;
if (isIterable) {
t = scope.getAnyTypeRef();
}
}
} else {
final TypeRef actualGenTypeRef = this.typeSystemHelper.getActualGeneratorReturnType(G, y);
if ((actualGenTypeRef != null)) {
t = this.typeSystemHelper.getGeneratorTNext(G, actualGenTypeRef);
}
}
if ((t == null)) {
t = RuleEnvironmentExtensions.anyTypeRef(G);
}
T = t;
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.ts.scoping.builtin.BuiltInTypeScope in project n4js by eclipse.
the class BuiltInTypeScopeTest method testLoadingBuiltInTypes.
@SuppressWarnings("javadoc")
@Test
public void testLoadingBuiltInTypes() {
BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet);
IEObjectDescription anyType = scope.getSingleElement(QualifiedName.create("any"));
Assert.assertNotNull(anyType);
String s = "";
for (Resource resource : resourceSet.getResources()) {
if (resource.getErrors().size() > 0) {
for (Diagnostic d : resource.getErrors()) {
s += "\n " + d.getMessage() + " at " + resource.getURI() + ":" + d.getLine();
}
}
}
Assert.assertEquals("Resources definine built-in types must have no error.", "", s);
}
use of org.eclipse.n4js.ts.scoping.builtin.BuiltInTypeScope in project n4js by eclipse.
the class BuiltInTypeScopePluginTest method testLoadingBuiltInTypes.
@SuppressWarnings("javadoc")
@Test
public void testLoadingBuiltInTypes() {
XtextResourceSet resourceSet = (XtextResourceSet) resourceSetProvider.get(null);
resourceSet.setClasspathURIContext(N4JSResource.class.getClassLoader());
BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet);
IEObjectDescription anyType = scope.getSingleElement(QualifiedName.create("any"));
Assert.assertNotNull(anyType);
}
use of org.eclipse.n4js.ts.scoping.builtin.BuiltInTypeScope in project n4js by eclipse.
the class MemberVisibilityChecker method getActualDeclaredReceiverType.
/**
* Returns the actual receiver type, which usually simply is the declared type of the receiver type. However, in
* case of classifier references, enums, or structural type references, the actual receiver may be differently
* computed.
*/
private Type getActualDeclaredReceiverType(EObject context, TypeRef receiverType, ResourceSet resourceSet) {
if (receiverType instanceof TypeTypeRef) {
final RuleEnvironment G = RuleEnvironmentExtensions.newRuleEnvironment(context);
return tsh.getStaticType(G, (TypeTypeRef) receiverType);
}
if (receiverType instanceof ThisTypeRef) {
ThisTypeRef thisTypeRef = (ThisTypeRef) receiverType;
if (thisTypeRef.isUseSiteStructuralTyping()) {
FunctionOrFieldAccessor foa = N4JSASTUtils.getContainingFunctionOrAccessor(thisTypeRef);
N4ClassifierDefinition classifier = EcoreUtil2.getContainerOfType(foa, N4ClassifierDefinition.class);
return classifier.getDefinedType();
}
}
if (receiverType instanceof FunctionTypeExpression) {
if (resourceSet == null)
return null;
// Change receiverType to implicit super class Function.
BuiltInTypeScope builtInTypeScope = BuiltInTypeScope.get(resourceSet);
TObjectPrototype functionType = builtInTypeScope.getFunctionType();
return functionType;
}
return receiverType.getDeclaredType();
}
use of org.eclipse.n4js.ts.scoping.builtin.BuiltInTypeScope in project n4js by eclipse.
the class N4JSScopingInstanceOfPrimitivTypeDiagnosis method diagnose.
/**
* Creates a {@link DiagnosticMessage} for instanceof expressions where the right-hand-side is a primitive type
* identifier.
*
* It is assumed that the given qualified name was extracted from the {@link IdentifierRef} on the rhs of the given
* relational expression.
*
* Returns null if not applicable.
*
* @param name
* The unresolved name of an IdentifierRef on the RHS of the expression.
*
* @param expression
* A pair of the instanceof-expression and the unresolved IdentifierRef.
*/
@Override
DiagnosticMessage diagnose(QualifiedName name, RelationalExpression expression) {
// only applicable for the instanceof operator
if (expression.getOp() != RelationalOperator.INSTANCEOF) {
return null;
}
// query built-in type scope for the unresolved name
BuiltInTypeScope builtInTypeScope = BuiltInTypeScope.get(expression.eResource().getResourceSet());
IEObjectDescription singleElement = builtInTypeScope.getSingleElement(name);
// if there is no primitive type with this name, this diagnosis is not applicable
if (null == singleElement) {
return null;
}
// if we can find a primitive type for the qualified name
if (singleElement.getEClass().getClassifierID() == TypesPackage.Literals.PRIMITIVE_TYPE.getClassifierID()) {
// create special error message
return createMessage(IssueCodes.TYS_INSTANCEOF_NOT_SUPPORTED_FOR_PRIMITIVE_TYPES, IssueCodes.getMessageForTYS_INSTANCEOF_NOT_SUPPORTED_FOR_PRIMITIVE_TYPES());
} else {
// the found element is not a primitive type, diagnosis not applicable
return null;
}
}
Aggregations