use of org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression in project n4js by eclipse.
the class N4JSEnumValidator method checkUsageOfStringBasedEnum.
/**
* See N4JS Specification, Req. IDE-41, Nr. 6.
*/
@Check
public void checkUsageOfStringBasedEnum(IdentifierRef identRef) {
final IdentifiableElement id = identRef.getId();
if (id == null || id.eIsProxy()) {
return;
}
if (!(id instanceof TEnum)) {
return;
}
final TEnum tEnum = (TEnum) id;
if (!AnnotationDefinition.STRING_BASED.hasAnnotation(tEnum)) {
return;
}
// we now have an IdentifierRef pointing to a string-based enum ...
final EObject parent = N4JSASTUtils.skipParenExpressionUpward(identRef.eContainer());
final ParameterizedPropertyAccessExpression parentPAE = parent instanceof ParameterizedPropertyAccessExpression ? (ParameterizedPropertyAccessExpression) parent : null;
final IdentifiableElement prop = parentPAE != null ? parentPAE.getProperty() : null;
if (prop != null) {
if (prop.eIsProxy()) {
// unnecessary duplicate error
return;
}
if (tEnum.getLiterals().contains(prop)) {
// reference to one of tEnum's literals -> valid usage!
return;
}
final RuleEnvironment G = RuleEnvironmentExtensions.newRuleEnvironment(identRef);
final TMember getterLiterals = RuleEnvironmentExtensions.n4StringBasedEnumType(G).findOwnedMember("literals", false, true);
if (prop == getterLiterals) {
// reference to static getter 'literals' in N4StringBasedEnum -> valid usage!
return;
}
}
// invalid usage!
addIssue(getMessageForENM_INVALID_USE_OF_STRINGBASED_ENUM(), identRef, ENM_INVALID_USE_OF_STRINGBASED_ENUM);
}
use of org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeSuperLiteral.
protected Result<TypeRef> applyRuleTypeSuperLiteral(final RuleEnvironment G, final RuleApplicationTrace _trace_, final SuperLiteral superLiteral) throws RuleFailedException {
// output parameter
TypeRef T = null;
final N4MemberDeclaration containingMemberDecl = EcoreUtil2.<N4MemberDeclaration>getContainerOfType(superLiteral.eContainer(), N4MemberDeclaration.class);
/* if (containingMemberDecl === null) { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } else { val containingClass = (containingMemberDecl.eContainer as N4ClassDeclaration).definedType as TClass; val superClass = G.getDeclaredOrImplicitSuperType(containingClass) var effectiveSuperClass = superClass if( containingClass.isStaticPolyfill ) { effectiveSuperClass = G.getDeclaredOrImplicitSuperType( superClass as TClass ) } { superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression if(containingMemberDecl.static) T = effectiveSuperClass?.createConstructorTypeRef else T = effectiveSuperClass?.createTypeRef if (T !== null) T = TypeUtils.enforceNominalTyping(T) } or { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } } or { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } */
{
RuleFailedException previousFailure = null;
try {
if ((containingMemberDecl == null)) {
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
} else {
EObject _eContainer = containingMemberDecl.eContainer();
Type _definedType = ((N4ClassDeclaration) _eContainer).getDefinedType();
final TClass containingClass = ((TClass) _definedType);
final TClassifier superClass = RuleEnvironmentExtensions.getDeclaredOrImplicitSuperType(G, containingClass);
TClassifier effectiveSuperClass = superClass;
boolean _isStaticPolyfill = containingClass.isStaticPolyfill();
if (_isStaticPolyfill) {
effectiveSuperClass = RuleEnvironmentExtensions.getDeclaredOrImplicitSuperType(G, ((TClass) superClass));
}
/* { superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression if(containingMemberDecl.static) T = effectiveSuperClass?.createConstructorTypeRef else T = effectiveSuperClass?.createTypeRef if (T !== null) T = TypeUtils.enforceNominalTyping(T) } or { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } */
{
try {
/* superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression */
if (!((superLiteral.eContainer() instanceof ParameterizedPropertyAccessExpression) || (superLiteral.eContainer() instanceof IndexedAccessExpression))) {
sneakyThrowRuleFailedException("superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression");
}
boolean _isStatic = containingMemberDecl.isStatic();
if (_isStatic) {
TypeRef _createConstructorTypeRef = null;
if (effectiveSuperClass != null) {
_createConstructorTypeRef = TypeUtils.createConstructorTypeRef(effectiveSuperClass);
}
T = _createConstructorTypeRef;
} else {
ParameterizedTypeRef _createTypeRef = null;
if (effectiveSuperClass != null) {
_createTypeRef = TypeUtils.createTypeRef(effectiveSuperClass);
}
T = _createTypeRef;
}
if ((T != null)) {
T = TypeUtils.enforceNominalTyping(T);
}
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
/* { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } */
{
try {
EObject _eContainer_1 = superLiteral.eContainer();
/* superLiteral.eContainer instanceof ParameterizedCallExpression */
if (!(_eContainer_1 instanceof ParameterizedCallExpression)) {
sneakyThrowRuleFailedException("superLiteral.eContainer instanceof ParameterizedCallExpression");
}
if (((containingMemberDecl instanceof N4MethodDeclaration) && Objects.equal(containingMemberDecl.getName(), "constructor"))) {
final TMethod ctor = this.containerTypesHelper.fromContext(superLiteral.eResource()).findConstructor(effectiveSuperClass);
ParameterizedTypeRef _createTypeRef_1 = null;
if (ctor != null) {
_createTypeRef_1 = TypeUtils.createTypeRef(ctor);
}
T = _createTypeRef_1;
} else {
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
}
} catch (Exception e_1) {
previousFailure = extractRuleFailedException(e_1);
EObject _eContainer_2 = superLiteral.eContainer();
/* superLiteral.eContainer instanceof NewExpression */
if (!(_eContainer_2 instanceof NewExpression)) {
sneakyThrowRuleFailedException("superLiteral.eContainer instanceof NewExpression");
}
}
}
}
}
}
} catch (Exception e_2) {
previousFailure = extractRuleFailedException(e_2);
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
}
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression in project n4js by eclipse.
the class ScopeXpectMethod method binding.
/**
* Checks that a given element is bound to something identified by (simple) qualified name. The check is designed as
* simple as possible. That is, simply the next following expression is tested, and within that we expect a property
* access or a direct identifiable element. The compared name is the simple qualified name, that is container (type)
* followed by elements name, without URIs of modules etc.
*/
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public //
void binding(//
@CommaSeparatedValuesExpectation ICommaSeparatedValuesExpectation expectation, //
ICrossEReferenceAndEObject arg1) {
EObject eobj = arg1.getEObject();
ParameterizedPropertyAccessExpression ppae = EcoreUtil2.getContainerOfType(eobj, ParameterizedPropertyAccessExpression.class);
IdentifiableElement element;
if (ppae != null) {
element = ppae.getProperty();
} else if (eobj instanceof IdentifiableElement) {
element = (IdentifiableElement) eobj;
} else {
throw new IllegalArgumentException("Cannot check binding for " + (eobj == null ? "null" : eobj.eClass().getName()));
}
String container = "";
if (element instanceof TMember) {
container = ((TMember) element).getContainingType().getName() + ".";
}
final String qn = container + element.getName();
// URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
expectation.assertEquals(Collections.singleton(qn));
}
use of org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression in project n4js by eclipse.
the class ParameterizedCallExpressionImpl method getReceiver.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Expression getReceiver() {
Expression _xifexpression = null;
Expression _target = this.getTarget();
if ((_target instanceof ParameterizedPropertyAccessExpression)) {
Expression _target_1 = this.getTarget();
_xifexpression = ((ParameterizedPropertyAccessExpression) _target_1).getTarget();
} else {
_xifexpression = null;
}
return _xifexpression;
}
use of org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression in project n4js by eclipse.
the class N4JSScopingConsumableMethodsDiagnosis method diagnose.
@Override
DiagnosticMessage diagnose(QualifiedName name, ParameterizedPropertyAccessExpression propertyAccess) {
// determine containing member declaration and classifier definition
N4MemberDeclaration containingMemberDeclaration = EcoreUtil2.getContainerOfType(propertyAccess, N4MemberDeclaration.class);
N4ClassifierDefinition classifierDefinition = EcoreUtil2.getContainerOfType(containingMemberDeclaration, N4ClassifierDefinition.class);
// if ancestors present and non-static context (no super in static context)
if (containingMemberDeclaration != null && !containingMemberDeclaration.isStatic() && classifierDefinition != null) {
// Get candidate methods
MemberList<TMember>.MemberIterable<TMethod> methods = containerTypesHelper.fromContext(propertyAccess).membersOfImplementedInterfacesForConsumption((TClassifier) classifierDefinition.getDefinedType()).methods();
boolean hasMethod = methods.stream().filter(// Filter for non-static non-abstract methods
m -> !m.isHasNoBody() && !m.isStatic()).anyMatch(m -> m.getName().equals(name.toString()));
if (hasMethod) {
return createMessage(IssueCodes.CLF_CANNOT_REFER_TO_DEFAULT_METHOD_WITH_SUPER, IssueCodes.getMessageForCLF_CANNOT_REFER_TO_DEFAULT_METHOD_WITH_SUPER());
}
}
return null;
}
Aggregations