01: //THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: //CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: //BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: //FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: //OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: //INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: //LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: //OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: //EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: //POSSIBILITY OF SUCH DAMAGE.
13: //
14: //Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package tudresden.ocl.codegen;
16:
17: import tudresden.ocl.check.types.OclState;
18: import tudresden.ocl.check.types.OclType;
19: import tudresden.ocl.check.types.Type;
20: import tudresden.ocl.parser.node.AFeaturePrimaryExpression;
21: import tudresden.ocl.parser.node.Node;
22:
23: /** This class extends original JavaCodeGenerator and fixes a few problems in it.
24: * We have been forced to declare this class in the tudresden.ocl.codegen package because it
25: * needs to use some featues with package visibility */
26: public class SpecialisedJavaCodeGenerator extends JavaCodeGenerator {
27: // We keep our own copies of these variables because the underlying class has them private */
28: private String mOclLibPackage = "tudresden.ocl.lib.";
29:
30: /** Overridden public constructor */
31: public SpecialisedJavaCodeGenerator(String instanceName,
32: String resultName) {
33: super (instanceName, resultName);
34: }
35:
36: /** This method is overridden to cater for the OclState */
37: public void outAFeaturePrimaryExpression(
38: AFeaturePrimaryExpression pe) {
39: Type oclType = tree.getNodeType(pe);
40: Node lParent = pe.parent();
41: while (oclType == null && lParent != null
42: && lParent.toString().equals(pe.toString())) {
43: oclType = tree.getNodeType(lParent);
44: lParent = lParent.parent();
45: }
46: if (oclType instanceof OclType) {
47: // type name
48: appendCode(createDecl("OclType", getVariable(pe))
49: + mOclLibPackage + "OclType.getOclTypeFor("
50: + instanceName + ", \"" + pe.toString().trim()
51: + "\");\n");
52: } else if (oclType instanceof OclState) {
53: // type name
54: appendCode(createDecl("OclState", getVariable(pe))
55: + mOclLibPackage + "Ocl.getOclStateFor(\""
56: + pe.toString().trim() + "\");\n");
57: } else
58: setVariable(pe, varMap.get(pe.toString().trim()));
59: }
60:
61: /** This method is duplicated here because the superclass has this method as private */
62: private String createDecl(String type, String variable) {
63: if (preVarTypes.containsKey(variable))
64: return variable + '=';
65: else if (type.indexOf('.') < 0)
66: return "final " + mOclLibPackage + type + ' ' + variable
67: + '=';
68: else
69: return "final " + type + ' ' + variable + '=';
70: }
71: }
|