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;
}
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;
}
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;
}
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;
}
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);
}
}
}
Aggregations