Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7944c53d569ddad025e2198c27f0cbbaff5be4a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/******************************************************************************
 * Copyright (c) 2005, 2020 Sven Efftinge, CEA LIST, Artal and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/ 
 * 
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors: 
 *     Sven Efftinge - Initial API and implementation
 *     Artem Tikhomirov (Borland) - Migration to OCL expressions
 *     Aurelien Didier (ARTAL) - aurelien.didier51@gmail.com - Bug 569174
 *****************************************************************************/
package org.eclipse.papyrus.gmf.internal.xpand.ast;

import java.util.Set;

import org.eclipse.ocl.cst.OCLExpressionCS;
import org.eclipse.papyrus.gmf.internal.xpand.model.AnalysationIssue;
import org.eclipse.papyrus.gmf.internal.xpand.model.EvaluationException;
import org.eclipse.papyrus.gmf.internal.xpand.model.ExecutionContext;
import org.eclipse.papyrus.gmf.internal.xpand.ocl.ExpressionHelper;

/**
 * @author Sven Efftinge
 */
public class ProtectStatement extends Statement {

    private final ExpressionHelper commentStart;

    private final ExpressionHelper commentEnd;

    private final Statement[] body;

    private final ExpressionHelper id;

    private final boolean disable;

    public ProtectStatement(final int start, final int end, final int line, final OCLExpressionCS commentStart,
            final OCLExpressionCS commentEnd, final Statement[] body, final OCLExpressionCS id, final boolean disable) {
        super(start, end, line);
        this.commentStart = new ExpressionHelper(commentStart, this);
        this.commentEnd = new ExpressionHelper(commentEnd, this);
        this.body = body;
        this.id = new ExpressionHelper(id, this);
        this.disable = disable;
    }

    public void analyze(final ExecutionContext ctx, final Set<AnalysationIssue> issues) {
        commentStart.analyze(ctx, issues);
        commentEnd.analyze(ctx, issues);
        id.analyze(ctx, issues);

        for (int i = 0; i < body.length; i++) {
            body[i].analyze(ctx, issues);
        }
    }

    @Override
    public void evaluateInternal(final ExecutionContext ctx) {
    	// FIXME REVISIT!!!
        final String cStart = nullSave(commentStart.evaluate(ctx));
        if (cStart == null) {
        	// Never will be here
			throw new EvaluationException("NullEvaluation!", commentStart);
		}
        final String cEnd = nullSave(commentEnd.evaluate(ctx));
        if (cEnd == null) {
        	// Never will be here
			throw new EvaluationException("NullEvaluation!", commentEnd);
		}
        final String idv = nullSave(id.evaluate(ctx));
        if (idv == null) {
        	// Never will be here
			throw new EvaluationException("NullEvaluation!", id);
		}

//        ProtectedRegion region = null;
//        if (ctx.getProtectedRegionResolver() != null) {
//            region = ctx.getProtectedRegionResolver().getProtectedRegion(idv);
//        } else {
//            throw new RuntimeException("No protected region resolver configured!");
//        }
//
//        if (region == null) {
//            region = ctx.getProtectedRegionResolver().createProtectedRegion(idv, disable);
//            ctx.getOutput().write(region.getStartString(cStart, cEnd));
//            for (int i = 0; i < body.length; i++) {
//                body[i].evaluate(ctx);
//            }
//            ctx.getOutput().write(region.getEndString(cStart, cEnd));
//        } else {
//            ctx.getOutput().write(region.getStartString(cStart, cEnd));
//            try {
//                ctx.getOutput().write(region.getBody(cStart, cEnd));
//            } catch (final ProtectedRegionSyntaxException e) {
//                throw new EvaluationException(e.getMessage(), this, id.getCST());
//            }
//            ctx.getOutput().write(region.getEndString(cStart, cEnd));
//        }

    }

    // FIXME STUPID CODE?! never returns null while each use of the method checks for null
    private String nullSave(final Object string) {
        return string != null ? string.toString() : "";
    }
    
    ExpressionHelper getCommentStart() {
    	return commentStart;
    }
    
    ExpressionHelper getCommentEnd() {
    	return commentEnd;
    }
    
    ExpressionHelper getId() {
    	return id;
    }
    
    Statement[] getBody() {
    	return body;
    }

}

Back to the top