Search in sources :

Example 6 with IdentifierRef

use of org.eclipse.n4js.n4JS.IdentifierRef in project n4js by eclipse.

the class PropertyNameValuePairSingleNameImpl method getName.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public String getName() {
    String _elvis = null;
    String _name = super.getName();
    if (_name != null) {
        _elvis = _name;
    } else {
        IdentifierRef _identifierRef = this.getIdentifierRef();
        String _idAsText = null;
        if (_identifierRef != null) {
            _idAsText = _identifierRef.getIdAsText();
        }
        _elvis = _idAsText;
    }
    return _elvis;
}
Also used : IdentifierRef(org.eclipse.n4js.n4JS.IdentifierRef)

Example 7 with IdentifierRef

use of org.eclipse.n4js.n4JS.IdentifierRef in project n4js by eclipse.

the class PropertyNameValuePairSingleNameImpl method basicSetIdentifierRef.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetIdentifierRef(IdentifierRef newIdentifierRef, NotificationChain msgs) {
    IdentifierRef oldIdentifierRef = identifierRef;
    identifierRef = newIdentifierRef;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, N4JSPackage.PROPERTY_NAME_VALUE_PAIR_SINGLE_NAME__IDENTIFIER_REF, oldIdentifierRef, newIdentifierRef);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) IdentifierRef(org.eclipse.n4js.n4JS.IdentifierRef)

Example 8 with IdentifierRef

use of org.eclipse.n4js.n4JS.IdentifierRef in project n4js by eclipse.

the class N4JSLinker method createProxy.

/**
 * Creates the proxy with a custom encoded URI format (starting with "|"). The object used to produce the encoded
 * URI are collected as tuple inside {@link N4JSResource}. Then the node text is checked if it is convertible to a
 * valid value. If there is a {@link BadEscapementException} is thrown then there is either a warning or an error
 * produced via the diagnosticProducer.
 *
 * @param resource
 *            the N4JSResource
 * @param obj
 *            the EObject containing the cross reference
 * @param node
 *            the node representing the EObject
 * @param eRef
 *            the cross reference in the domain model
 * @param xref
 *            the cross reference in the node model
 * @param diagnosticProducer
 *            to produce errors or warnings
 * @return the created proxy
 */
private EObject createProxy(N4JSResource resource, EObject obj, INode node, EReference eRef, CrossReference xref, IDiagnosticProducer diagnosticProducer) {
    final URI uri = resource.getURI();
    /*
		 * as otherwise with 0 the EObjectDescription created for Script would be fetched
		 */
    final int fragmentNumber = resource.addLazyProxyInformation(obj, eRef, node);
    final URI encodedLink = uri.appendFragment("|" + fragmentNumber);
    EClass referenceType = findInstantiableCompatible(eRef.getEReferenceType());
    final EObject proxy = EcoreUtil.create(referenceType);
    ((InternalEObject) proxy).eSetProxyURI(encodedLink);
    AbstractElement terminal = xref.getTerminal();
    if (!(terminal instanceof RuleCall)) {
        throw new IllegalArgumentException(String.valueOf(xref));
    }
    AbstractRule rule = ((RuleCall) terminal).getRule();
    try {
        String tokenText = NodeModelUtils.getTokenText(node);
        Object value = valueConverterService.toValue(tokenText, rule.getName(), node);
        if (obj instanceof IdentifierRef && value instanceof String) {
            ((IdentifierRef) obj).setIdAsText((String) value);
        } else if (obj instanceof LabelRef && value instanceof String) {
            ((LabelRef) obj).setLabelAsText((String) value);
        } else if (obj instanceof ParameterizedPropertyAccessExpression && value instanceof String) {
            ((ParameterizedPropertyAccessExpression) obj).setPropertyAsText((String) value);
        } else if (obj instanceof NamedImportSpecifier && value instanceof String) {
            ((NamedImportSpecifier) obj).setImportedElementAsText((String) value);
        } else if ((obj instanceof JSXPropertyAttribute) && (value instanceof String)) {
            ((JSXPropertyAttribute) obj).setPropertyAsText((String) value);
        } else {
            setOtherElementAsText(tokenText, obj, value);
        }
    } catch (BadEscapementException e) {
        diagnosticProducer.addDiagnostic(new DiagnosticMessage(e.getMessage(), e.getSeverity(), e.getIssueCode(), Strings.EMPTY_ARRAY));
    } catch (N4JSValueConverterException vce) {
        diagnosticProducer.addDiagnostic(new DiagnosticMessage(vce.getMessage(), vce.getSeverity(), vce.getIssueCode(), Strings.EMPTY_ARRAY));
    } catch (N4JSValueConverterWithValueException vcwve) {
        diagnosticProducer.addDiagnostic(new DiagnosticMessage(vcwve.getMessage(), vcwve.getSeverity(), vcwve.getIssueCode(), Strings.EMPTY_ARRAY));
    }
    return proxy;
}
Also used : ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) NamedImportSpecifier(org.eclipse.n4js.n4JS.NamedImportSpecifier) AbstractElement(org.eclipse.xtext.AbstractElement) JSXPropertyAttribute(org.eclipse.n4js.n4JS.JSXPropertyAttribute) URI(org.eclipse.emf.common.util.URI) LabelRef(org.eclipse.n4js.n4JS.LabelRef) N4JSValueConverterWithValueException(org.eclipse.n4js.conversion.N4JSValueConverterWithValueException) RuleCall(org.eclipse.xtext.RuleCall) EClass(org.eclipse.emf.ecore.EClass) DiagnosticMessage(org.eclipse.xtext.diagnostics.DiagnosticMessage) BadEscapementException(org.eclipse.n4js.conversion.AbstractN4JSStringValueConverter.BadEscapementException) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) N4JSValueConverterException(org.eclipse.n4js.conversion.N4JSValueConverterException) AbstractRule(org.eclipse.xtext.AbstractRule) InternalEObject(org.eclipse.emf.ecore.InternalEObject) IdentifierRef(org.eclipse.n4js.n4JS.IdentifierRef)

Example 9 with IdentifierRef

use of org.eclipse.n4js.n4JS.IdentifierRef in project n4js by eclipse.

the class StaticWriteAccessFilterScope method isAccepted.

@Override
protected boolean isAccepted(IEObjectDescription description) {
    EObject proxyOrInstance = description.getEObjectOrProxy();
    if (proxyOrInstance instanceof TMember && !proxyOrInstance.eIsProxy()) {
        TMember member = (TMember) proxyOrInstance;
        // this particular message to hide the better one.
        if (member.isStatic() && member.isWriteable() && /* i.e. (member.isField(), not const || member.isSetter()) */
        isWriteAccess()) {
            ContainerType<?> memberType = member.getContainingType();
            memberTypeName = memberType.getName();
            // Access only allowed for Direct access, so AST must be IdentifierRef.
            final boolean isTargetGivenByIdentifier = getTarget() instanceof IdentifierRef;
            if (!isTargetGivenByIdentifier) {
                // Not an IdentifierRef --> disallowed for write access.
                return false;
            }
            IdentifierRef idref = (IdentifierRef) getTarget();
            // this also covers aliased imports:
            if (idref.getId().getName().equals(memberTypeName)) {
                // correct name.
                return true;
            } else {
                // wrong name, disallowed
                // search for alias, for better error reporting.
                Script sc = EcoreUtil2.getContainerOfType(context, Script.class);
                Optional<NamedImportSpecifier> namedImport = sc.getScriptElements().stream().filter(se -> se instanceof ImportDeclaration).map(se -> (ImportDeclaration) se).flatMap(idecl -> {
                    return idecl.getImportSpecifiers().stream().filter(is -> is instanceof NamedImportSpecifier).map(is -> (NamedImportSpecifier) is);
                }).filter(s -> s.getImportedElement() == memberType).findFirst();
                if (namedImport.isPresent()) {
                    // if alias is present assign, otherwise null will be passed through
                    memberTypeAlias = namedImport.get().getAlias();
                }
                return false;
            }
        }
    }
    return true;
}
Also used : IndexedAccessExpression(org.eclipse.n4js.n4JS.IndexedAccessExpression) FilterWithErrorMarkerScope(org.eclipse.n4js.xtext.scoping.FilterWithErrorMarkerScope) IScope(org.eclipse.xtext.scoping.IScope) TMember(org.eclipse.n4js.ts.types.TMember) EObject(org.eclipse.emf.ecore.EObject) Script(org.eclipse.n4js.n4JS.Script) IEObjectDescriptionWithError(org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError) NamedImportSpecifier(org.eclipse.n4js.n4JS.NamedImportSpecifier) ContainerType(org.eclipse.n4js.ts.types.ContainerType) ExpressionExtensions(org.eclipse.n4js.n4JS.extensions.ExpressionExtensions) ImportDeclaration(org.eclipse.n4js.n4JS.ImportDeclaration) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) IdentifierRef(org.eclipse.n4js.n4JS.IdentifierRef) Optional(java.util.Optional) Expression(org.eclipse.n4js.n4JS.Expression) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Script(org.eclipse.n4js.n4JS.Script) NamedImportSpecifier(org.eclipse.n4js.n4JS.NamedImportSpecifier) EObject(org.eclipse.emf.ecore.EObject) ImportDeclaration(org.eclipse.n4js.n4JS.ImportDeclaration) TMember(org.eclipse.n4js.ts.types.TMember) IdentifierRef(org.eclipse.n4js.n4JS.IdentifierRef)

Example 10 with IdentifierRef

use of org.eclipse.n4js.n4JS.IdentifierRef in project n4js by eclipse.

the class FunctionValidationHelper method internalCheckFormalParameters.

/**
 * IDEBUG-211, IDE-145</br>
 * Check for variadic, default, and missing initializer forward references in formal parameters. </br>
 * Note: This method is called for the {@link N4JSFunctionValidator}.
 */
public static <T extends EObject> void internalCheckFormalParameters(T[] fpars, Predicate<T> variadic, Predicate<T> hasInitAssgn, Function<T, String> name, TripleConsumer<String, String, EObject> issueConsumer) {
    List<T> fparsL = Arrays.asList(fpars);
    for (T fPar : fparsL) {
        // check 1. and 2. only if the we are not in a FunctionDefinition to avoid double checking!
        // Parameters of FunctionDefintions are also checked by the ASTStructureValidator,
        // which invokes the following method already for parameter.
        boolean isInFunctionDefinition = fPar.eContainer() instanceof FunctionDefinition;
        if (!isInFunctionDefinition)
            internalCheckFormalParameter(fparsL, fPar, variadic, hasInitAssgn, issueConsumer);
        // 3. Reference to succeeding parameter
        if (hasInitAssgn.test(fPar)) {
            int fpPos = fparsL.indexOf(fPar);
            List<IdentifierRef> irs = EcoreUtil2.getAllContentsOfType(fPar, IdentifierRef.class);
            for (IdentifierRef ir : irs) {
                if (fparsL.indexOf(ir.getId()) >= fpPos) {
                    String msg = getMessageForFUN_PARAM_INITIALIZER_ILLEGAL_FORWARD_REFERENCE();
                    issueConsumer.accept(msg, FUN_PARAM_INITIALIZER_ILLEGAL_FORWARD_REFERENCE, ir);
                }
            }
        }
    }
    // 4. Implicit default formal parameters
    boolean initAssgnVisited = false;
    Iterator<T> iter = fparsL.iterator();
    while (iter.hasNext() && !initAssgnVisited) {
        initAssgnVisited = hasInitAssgn.test(iter.next());
    }
    while (initAssgnVisited && iter.hasNext()) {
        T fpar = iter.next();
        if (!hasInitAssgn.test(fpar) && !variadic.test(fpar)) {
            String msg = getMessageForFUN_PARAM_IMPLICIT_DEFAULT_PARAM(name.apply(fpar));
            issueConsumer.accept(msg, FUN_PARAM_IMPLICIT_DEFAULT_PARAM, fpar);
        }
    }
}
Also used : FUN_PARAM_VARIADIC_ONLY_LAST(org.eclipse.n4js.validation.IssueCodes.FUN_PARAM_VARIADIC_ONLY_LAST) IssueCodes.getMessageForFUN_PARAM_VARIADIC_ONLY_LAST(org.eclipse.n4js.validation.IssueCodes.getMessageForFUN_PARAM_VARIADIC_ONLY_LAST) FunctionDefinition(org.eclipse.n4js.n4JS.FunctionDefinition) IdentifierRef(org.eclipse.n4js.n4JS.IdentifierRef)

Aggregations

IdentifierRef (org.eclipse.n4js.n4JS.IdentifierRef)11 ParameterizedPropertyAccessExpression (org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression)4 IndexedAccessExpression (org.eclipse.n4js.n4JS.IndexedAccessExpression)3 NamedImportSpecifier (org.eclipse.n4js.n4JS.NamedImportSpecifier)3 VariableDeclaration (org.eclipse.n4js.n4JS.VariableDeclaration)3 IdentifiableElement (org.eclipse.n4js.ts.types.IdentifiableElement)3 EObject (org.eclipse.emf.ecore.EObject)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)2 AssignmentExpression (org.eclipse.n4js.n4JS.AssignmentExpression)2 AwaitExpression (org.eclipse.n4js.n4JS.AwaitExpression)2 BinaryBitwiseExpression (org.eclipse.n4js.n4JS.BinaryBitwiseExpression)2 BinaryLogicalExpression (org.eclipse.n4js.n4JS.BinaryLogicalExpression)2 CastExpression (org.eclipse.n4js.n4JS.CastExpression)2 CommaExpression (org.eclipse.n4js.n4JS.CommaExpression)2 ConditionalExpression (org.eclipse.n4js.n4JS.ConditionalExpression)2 EqualityExpression (org.eclipse.n4js.n4JS.EqualityExpression)2 Expression (org.eclipse.n4js.n4JS.Expression)2 FunctionExpression (org.eclipse.n4js.n4JS.FunctionExpression)2 ImportDeclaration (org.eclipse.n4js.n4JS.ImportDeclaration)2