Search in sources :

Example 21 with IdentifiableElement

use of org.eclipse.n4js.ts.types.IdentifiableElement in project n4js by eclipse.

the class UsedBeforeDeclaredAnalyserFastVersion method visit.

@Override
protected void visit(ControlFlowElement cfe) {
    if (cfe instanceof VariableDeclaration) {
        checkLists.put((VariableDeclaration) cfe, new HashSet<>());
    }
    if (cfe instanceof IdentifierRef) {
        IdentifierRef ir = (IdentifierRef) cfe;
        IdentifiableElement id = ir.getId();
        if (id instanceof TVariable) {
            TVariable tvar = (TVariable) id;
            id = (VariableDeclaration) tvar.getAstElement();
        }
        Set<IdentifierRef> refs = checkLists.get(id);
        if (refs != null) {
            refs.add(ir);
        }
    }
}
Also used : TVariable(org.eclipse.n4js.ts.types.TVariable) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) VariableDeclaration(org.eclipse.n4js.n4JS.VariableDeclaration) IdentifierRef(org.eclipse.n4js.n4JS.IdentifierRef)

Example 22 with IdentifiableElement

use of org.eclipse.n4js.ts.types.IdentifiableElement in project n4js by eclipse.

the class SymbolFactory method getUndefined.

/**
 * @return a {@link Symbol} that represents {@code undefined}
 */
public Symbol getUndefined() {
    if (undefined == null) {
        IdentifiableElement ieUndefined = TypesFactory.eINSTANCE.createIdentifiableElement();
        IdentifierRef irUndefined = N4JSFactory.eINSTANCE.createIdentifierRef();
        irUndefined.setId(ieUndefined);
        ieUndefined.setName("undefined");
        undefined = create(irUndefined);
    }
    return undefined;
}
Also used : IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) IdentifierRef(org.eclipse.n4js.n4JS.IdentifierRef)

Example 23 with IdentifiableElement

use of org.eclipse.n4js.ts.types.IdentifiableElement in project n4js by eclipse.

the class N4TypeDeclarationImpl method getExportedName.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public String getExportedName() {
    boolean _isExported = this.isExported();
    if (_isExported) {
        EObject _eContainer = this.eContainer();
        final ExportDeclaration exportDecl = ((ExportDeclaration) _eContainer);
        boolean _isDefaultExport = exportDecl.isDefaultExport();
        if (_isDefaultExport) {
            return "default";
        }
        final ExportableElement me = this;
        String _switchResult = null;
        boolean _matched = false;
        if (me instanceof NamedElement) {
            _matched = true;
            _switchResult = ((NamedElement) me).getName();
        }
        if (!_matched) {
            if (me instanceof IdentifiableElement) {
                _matched = true;
                _switchResult = ((IdentifiableElement) me).getName();
            }
        }
        return _switchResult;
    }
    return null;
}
Also used : ExportableElement(org.eclipse.n4js.n4JS.ExportableElement) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) ExportDeclaration(org.eclipse.n4js.n4JS.ExportDeclaration) NamedElement(org.eclipse.n4js.n4JS.NamedElement)

Example 24 with IdentifiableElement

use of org.eclipse.n4js.ts.types.IdentifiableElement in project n4js by eclipse.

the class SpecADocXpectMethod method specADoc.

/**
 * Checks that an element/expression produces a certain specification string. Usage:
 *
 * <pre>
 * /* X-PECT specADoc at 'location' ---
 * expected spec output
 * --- * /
 * </pre>
 *
 * The location (at) is optional.
 *
 * Note that the X-PECT comment must be written <b>before</b> the JSDoc comment of the element.
 *
 * @param arg1
 *            the location identified by the offset.
 */
@Xpect
@ParameterParser(syntax = "('at' arg1=STRING)?")
public void specADoc(@StringExpectation(caseSensitive = true) IStringExpectation expectation, IEObjectCoveringRegion arg1) {
    if (expectation == null) {
        throw new IllegalStateException("No expectation specified, add '--- expected expectation ---");
    }
    IdentifiableElement element = getIdentifiableElement(arg1);
    SpecIdentifiableElementSection src = new SpecIdentifiableElementSection(element, repoPathHolder);
    String actual = formatter.createSpecRegionString(src, Collections.emptyMap()).toString();
    expectation.assertEquals(actual);
}
Also used : IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) SpecIdentifiableElementSection(org.eclipse.n4js.jsdoc2spec.adoc.SpecIdentifiableElementSection) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 25 with IdentifiableElement

use of org.eclipse.n4js.ts.types.IdentifiableElement in project n4js by eclipse.

the class InternalTypeSystem method applyRuleThisTypeRefEObject.

protected Result<TypeRef> applyRuleThisTypeRefEObject(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EObject location) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    final FunctionOrFieldAccessor containingFunctionOrAccessor = N4JSASTUtils.getContainingFunctionOrAccessor(location);
    boolean _matched = false;
    if (containingFunctionOrAccessor instanceof ArrowFunction) {
        _matched = true;
        /* G |~ containingFunctionOrAccessor ~> T */
        Result<TypeRef> result = thisTypeRefInternal(G, _trace_, ((ArrowFunction) containingFunctionOrAccessor));
        checkAssignableTo(result.getFirst(), TypeRef.class);
        T = (TypeRef) result.getFirst();
    }
    if (!_matched) {
        IdentifiableElement _definedFunctionOrAccessor = null;
        if (containingFunctionOrAccessor != null) {
            _definedFunctionOrAccessor = containingFunctionOrAccessor.getDefinedFunctionOrAccessor();
        }
        final IdentifiableElement containingTFunctionOrAccessor = _definedFunctionOrAccessor;
        final TypeRef declaredThisType = TypeSystemHelper.declaredThisType(containingTFunctionOrAccessor);
        if ((declaredThisType != null)) {
            if ((declaredThisType instanceof ParameterizedTypeRef)) {
                /* G |~ declaredThisType ~> T */
                Result<TypeRef> result = thisTypeRefInternal(G, _trace_, ((ParameterizedTypeRef) declaredThisType));
                checkAssignableTo(result.getFirst(), TypeRef.class);
                T = (TypeRef) result.getFirst();
            } else {
                T = declaredThisType;
            }
        } else {
            final ThisTarget thisTarget = N4JSASTUtils.getProbableThisTarget(location);
            boolean _matched_1 = false;
            if (thisTarget instanceof ObjectLiteral) {
                _matched_1 = true;
                /* G |- thisTarget: T */
                Result<TypeRef> result_1 = typeInternal(G, _trace_, ((ObjectLiteral) thisTarget));
                checkAssignableTo(result_1.getFirst(), TypeRef.class);
                T = (TypeRef) result_1.getFirst();
            }
            if (!_matched_1) {
                if (thisTarget instanceof N4ClassifierDefinition) {
                    _matched_1 = true;
                    Type thisTargetDEFTYPE = ((N4ClassifierDefinition) thisTarget).getDefinedType();
                    if ((thisTarget instanceof N4ClassDeclaration)) {
                        final TClass clazz = ((N4ClassDeclaration) thisTarget).getDefinedTypeAsClass();
                        if (((clazz != null) && clazz.isStaticPolyfill())) {
                            final Type actualClazz = clazz.getSuperClassRef().getDeclaredType();
                            if ((actualClazz != null)) {
                                thisTargetDEFTYPE = actualClazz;
                            }
                        }
                    }
                    if ((thisTargetDEFTYPE != null)) {
                        final FunctionDefinition containingFunction = N4JSASTUtils.getContainingFunction(location);
                        if (((containingFunction instanceof N4MethodDeclaration) && ((N4MemberDeclaration) containingFunction).isStatic())) {
                            boolean _isInReturnDeclaration_Of_StaticMethod = RuleEnvironmentExtensions.isInReturnDeclaration_Of_StaticMethod(location, ((N4MethodDeclaration) containingFunction));
                            if (_isInReturnDeclaration_Of_StaticMethod) {
                                /* G |~ thisTargetDEFTYPE.ref ~> T */
                                TypeRef _ref = TypeExtensions.ref(thisTargetDEFTYPE);
                                Result<TypeRef> result_1 = thisTypeRefInternal(G, _trace_, _ref);
                                checkAssignableTo(result_1.getFirst(), TypeRef.class);
                                T = (TypeRef) result_1.getFirst();
                            } else {
                                boolean _isInBody_Of_StaticMethod = RuleEnvironmentExtensions.isInBody_Of_StaticMethod(location, ((N4MethodDeclaration) containingFunction));
                                if (_isInBody_Of_StaticMethod) {
                                    T = TypeUtils.createClassifierBoundThisTypeRef(TypeUtils.createTypeTypeRef(TypeExtensions.ref(thisTargetDEFTYPE), false));
                                } else {
                                    T = TypeUtils.createConstructorTypeRef(thisTargetDEFTYPE);
                                }
                            }
                        } else {
                            final N4FieldDeclaration n4Field = EcoreUtil2.<N4FieldDeclaration>getContainerOfType(location, N4FieldDeclaration.class);
                            if (((n4Field != null) && n4Field.isStatic())) {
                                T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
                            } else {
                                final N4GetterDeclaration n4Getter = EcoreUtil2.<N4GetterDeclaration>getContainerOfType(location, N4GetterDeclaration.class);
                                if (((n4Getter != null) && n4Getter.isStatic())) {
                                    T = TypeUtils.createConstructorTypeRef(thisTargetDEFTYPE);
                                } else {
                                    final N4SetterDeclaration n4Setter = EcoreUtil2.<N4SetterDeclaration>getContainerOfType(location, N4SetterDeclaration.class);
                                    if (((n4Setter != null) && n4Setter.isStatic())) {
                                        T = TypeUtils.createConstructorTypeRef(thisTargetDEFTYPE);
                                    } else {
                                        /* G |~ thisTargetDEFTYPE.ref ~> T */
                                        TypeRef _ref_1 = TypeExtensions.ref(thisTargetDEFTYPE);
                                        Result<TypeRef> result_2 = thisTypeRefInternal(G, _trace_, _ref_1);
                                        checkAssignableTo(result_2.getFirst(), TypeRef.class);
                                        T = (TypeRef) result_2.getFirst();
                                    }
                                }
                            }
                        }
                    } else {
                        T = RuleEnvironmentExtensions.anyTypeRefDynamic(G);
                    }
                }
            }
            if (!_matched_1) {
                boolean _hasGlobalObject = this.jsVariantHelper.hasGlobalObject(location);
                if (_hasGlobalObject) {
                    T = RuleEnvironmentExtensions.globalObjectTypeRef(G);
                } else {
                    T = RuleEnvironmentExtensions.undefinedTypeRef(G);
                }
            }
        }
    }
    return new Result<TypeRef>(T);
}
Also used : ObjectLiteral(org.eclipse.n4js.n4JS.ObjectLiteral) FunctionOrFieldAccessor(org.eclipse.n4js.n4JS.FunctionOrFieldAccessor) N4FieldDeclaration(org.eclipse.n4js.n4JS.N4FieldDeclaration) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) N4GetterDeclaration(org.eclipse.n4js.n4JS.N4GetterDeclaration) ArrowFunction(org.eclipse.n4js.n4JS.ArrowFunction) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) N4MemberDeclaration(org.eclipse.n4js.n4JS.N4MemberDeclaration) N4ClassDeclaration(org.eclipse.n4js.n4JS.N4ClassDeclaration) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) N4SetterDeclaration(org.eclipse.n4js.n4JS.N4SetterDeclaration) Type(org.eclipse.n4js.ts.types.Type) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) VoidType(org.eclipse.n4js.ts.types.VoidType) AnyType(org.eclipse.n4js.ts.types.AnyType) ModuleNamespaceVirtualType(org.eclipse.n4js.ts.types.ModuleNamespaceVirtualType) NullType(org.eclipse.n4js.ts.types.NullType) UndefinedType(org.eclipse.n4js.ts.types.UndefinedType) ContainerType(org.eclipse.n4js.ts.types.ContainerType) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) N4ClassifierDefinition(org.eclipse.n4js.n4JS.N4ClassifierDefinition) N4MethodDeclaration(org.eclipse.n4js.n4JS.N4MethodDeclaration) FunctionDefinition(org.eclipse.n4js.n4JS.FunctionDefinition) TClass(org.eclipse.n4js.ts.types.TClass) ThisTarget(org.eclipse.n4js.n4JS.ThisTarget)

Aggregations

IdentifiableElement (org.eclipse.n4js.ts.types.IdentifiableElement)27 EObject (org.eclipse.emf.ecore.EObject)12 ExportDeclaration (org.eclipse.n4js.n4JS.ExportDeclaration)7 ExportableElement (org.eclipse.n4js.n4JS.ExportableElement)6 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)6 NamedElement (org.eclipse.n4js.n4JS.NamedElement)5 ParameterizedPropertyAccessExpression (org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression)5 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)5 BoundThisTypeRef (org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef)5 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)5 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)5 FunctionTypeRef (org.eclipse.n4js.ts.typeRefs.FunctionTypeRef)5 StaticBaseTypeRef (org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef)5 StructuralTypeRef (org.eclipse.n4js.ts.typeRefs.StructuralTypeRef)5 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)5 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)5 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)5 UnknownTypeRef (org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)5 StructuralTypingResult (org.eclipse.n4js.typesystem.StructuralTypingResult)5 Result (org.eclipse.xsemantics.runtime.Result)5