Search in sources :

Example 1 with N4TypeDeclaration

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;
}
Also used : ExportedVariableDeclaration(org.eclipse.n4js.n4JS.ExportedVariableDeclaration) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) N4MemberDeclaration(org.eclipse.n4js.n4JS.N4MemberDeclaration) ExportDeclaration(org.eclipse.n4js.n4JS.ExportDeclaration) FunctionDeclaration(org.eclipse.n4js.n4JS.FunctionDeclaration) VariableStatement(org.eclipse.n4js.n4JS.VariableStatement) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) Expression(org.eclipse.n4js.n4JS.Expression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) ExportedVariableDeclaration(org.eclipse.n4js.n4JS.ExportedVariableDeclaration) VariableDeclaration(org.eclipse.n4js.n4JS.VariableDeclaration) N4TypeDeclaration(org.eclipse.n4js.n4JS.N4TypeDeclaration) TMember(org.eclipse.n4js.ts.types.TMember)

Aggregations

ExportDeclaration (org.eclipse.n4js.n4JS.ExportDeclaration)1 ExportedVariableDeclaration (org.eclipse.n4js.n4JS.ExportedVariableDeclaration)1 Expression (org.eclipse.n4js.n4JS.Expression)1 FunctionDeclaration (org.eclipse.n4js.n4JS.FunctionDeclaration)1 N4MemberDeclaration (org.eclipse.n4js.n4JS.N4MemberDeclaration)1 N4TypeDeclaration (org.eclipse.n4js.n4JS.N4TypeDeclaration)1 ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)1 ParameterizedPropertyAccessExpression (org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression)1 VariableDeclaration (org.eclipse.n4js.n4JS.VariableDeclaration)1 VariableStatement (org.eclipse.n4js.n4JS.VariableStatement)1 IdentifiableElement (org.eclipse.n4js.ts.types.IdentifiableElement)1 TMember (org.eclipse.n4js.ts.types.TMember)1