use of org.eclipse.n4js.n4JS.N4TypeDeclaration 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;
}
Aggregations