use of org.eclipse.n4js.n4JS.N4MemberDeclaration in project n4js by eclipse.
the class N4JSReferenceQueryExecutor method getTargetURIs.
/**
* Here, we add overridden/overriding members or super/subclasses if needed depending on user preferences when
* finding references.
*/
@Override
protected Iterable<URI> getTargetURIs(EObject primaryTarget) {
@SuppressWarnings("restriction") Iterable<URI> originalResult = super.getTargetURIs(primaryTarget);
List<URI> newResult = Lists.newArrayList(originalResult);
if (primaryTarget instanceof LiteralOrComputedPropertyName) {
primaryTarget = primaryTarget.eContainer();
}
// Handling for various configurations e.g. consider overriden members
List<EObject> realTargets = new ArrayList<>();
if (primaryTarget instanceof TMember && ((TMember) primaryTarget).isComposed()) {
// In case of composed member, add the constituent members instead.
List<TMember> constituentMembers = ((TMember) primaryTarget).getConstituentMembers();
for (TMember constituentMember : constituentMembers) {
realTargets.add(constituentMember);
}
} else {
// Standard case
realTargets.add(primaryTarget);
}
for (EObject realTarget : realTargets) {
if (N4JSReferenceQueryExecutor.considerOverridenMethods) {
// Add overriden members
if (realTarget instanceof N4MemberDeclaration || // Only consider members within a classifier.Ignore TStructMember.
(realTarget instanceof TMember && realTarget.eContainer() instanceof TClassifier)) {
TMember tmember;
if (primaryTarget instanceof N4MemberDeclaration) {
tmember = ((N4MemberDeclaration) primaryTarget).getDefinedTypeElement();
} else {
tmember = (TMember) primaryTarget;
}
for (TMember inheritedOrImplementedMember : getInheritedAndImplementedMembers(tmember)) {
URI uri = EcoreUtil2.getPlatformResourceOrNormalizedURI(inheritedOrImplementedMember);
newResult.add(uri);
}
}
}
}
return newResult;
}
use of org.eclipse.n4js.n4JS.N4MemberDeclaration 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.N4MemberDeclaration 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;
}
use of org.eclipse.n4js.n4JS.N4MemberDeclaration in project n4js by eclipse.
the class AccessModifierXpectMethod method calculateActual.
private String calculateActual(EObject context) {
String actual = null;
if (context instanceof TMember) {
TMember tMember = (TMember) context;
actual = tMember.getMemberAccessModifier().getName();
} else {
FunctionDeclaration functionDeclaration = EcoreUtil2.getContainerOfType(context, FunctionDeclaration.class);
if (functionDeclaration != null) {
actual = functionDeclaration.getDefinedType().getTypeAccessModifier().getName();
} else {
VariableStatement variableStatement = EcoreUtil2.getContainerOfType(context, VariableStatement.class);
if (variableStatement != null) {
context = variableStatement.getVarDecl().get(0);
if (context instanceof ExportedVariableDeclaration) {
actual = ((ExportedVariableDeclaration) context).getDefinedVariable().getTypeAccessModifier().getName();
} else if (context instanceof VariableDeclaration) {
actual = "private";
}
} else if (context instanceof ExportDeclaration) {
context = ((ExportDeclaration) context).getExportedElement();
actual = calculateActual(context);
} else if (context instanceof ParameterizedPropertyAccessExpression) {
ParameterizedPropertyAccessExpression ppae = (ParameterizedPropertyAccessExpression) context;
IdentifiableElement ie = ppae.getProperty();
actual = calculateActual(ie);
} else if (context instanceof ParameterizedCallExpression) {
ParameterizedCallExpression pce = (ParameterizedCallExpression) context;
Expression targetExpr = pce.getTarget();
actual = calculateActual(targetExpr);
} else {
N4MemberDeclaration member = EcoreUtil2.getContainerOfType(context, N4MemberDeclaration.class);
N4TypeDeclaration type = EcoreUtil2.getContainerOfType(context, N4TypeDeclaration.class);
if (type == null && member == null) {
actual = "no element with access modifier found";
} else if (type != null && (member == null || EcoreUtil.isAncestor(member, type))) {
actual = type.getDefinedType().getTypeAccessModifier().getName();
} else {
actual = member.getDefinedTypeElement().getMemberAccessModifier().getName();
}
}
}
}
return actual;
}
use of org.eclipse.n4js.n4JS.N4MemberDeclaration 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);
}
Aggregations