1 package org.andromda.translation.ocl.syntax;
2
3 import org.andromda.core.translation.TranslationUtils;
4
5 /**
6 * Contains the patterns matching reserved features of the OCL language.
7 *
8 * @author Chad Brandon
9 */
10 public class OCLFeatures
11 {
12 /**
13 * Matches on the <code>allInstances</code> feature.
14 */
15 private static final String ALL_INSTANCES = "(\\s*\\w*\\s*(\\w+|::)*)?\\s*allInstances\\s*\\(\\s*\\)";
16
17 /**
18 * Matches on the <code>oclIsKindOf</code> feature.
19 */
20 private static final String OCL_IS_KIND_OF = "oclIsKindOf\\s*\\(\\s*" + OCLPatterns.SCOPE_PATH
21 + "\\s*\\)\\s*";
22
23 /**
24 * Matches on the <code>oclIsTypeOf</code> feature.
25 */
26 private static final String OCL_IS_TYPE_OF = "oclIsTypeOf\\s*\\(\\s*" + OCLPatterns.SCOPE_PATH
27 + "\\s*\\)\\s*";
28
29 /**
30 * Matches on the <code>concat</code> feature.
31 */
32 private static final String CONCAT = "concat\\s*\\(\\s*" + OCLPatterns.NAVIGATIONAL_PATH
33 + "\\s*\\)\\s*";
34
35 /**
36 * Matches on any of the features.
37 */
38 private static final String ALL_PATTERNS = ALL_INSTANCES + '|' + OCL_IS_KIND_OF + '|'
39 + OCL_IS_TYPE_OF + '|' + CONCAT;
40
41 /**
42 * Indicates if the expression is an <em>allInstances</em>. OCL feature.
43 *
44 * @param expression the expression to evaluate.
45 * @return true/false
46 */
47 public static boolean isAllInstances(Object expression)
48 {
49 return TranslationUtils.deleteWhitespace(expression).matches(OCLFeatures.ALL_INSTANCES);
50 }
51
52 /**
53 * Indicates if the expression is an <em>concat</em>. OCL feature.
54 *
55 * @param expression the expression to evaluate.
56 * @return true/false
57 */
58 public static boolean isConcat(Object expression)
59 {
60 return TranslationUtils.deleteWhitespace(expression).matches(OCLFeatures.CONCAT);
61 }
62
63 /**
64 * Indicates if the expression is an <em>oclIsTypeOf</em>. OCL feature.
65 *
66 * @param expression the expression to evaluate.
67 * @return true/false
68 */
69 public static boolean isOclIsTypeOf(Object expression)
70 {
71 return TranslationUtils.deleteWhitespace(expression).matches(OCLFeatures.OCL_IS_TYPE_OF);
72 }
73
74 /**
75 * Indicates if the expression is an <em>oclIsKindOf</em>. OCL feature.
76 *
77 * @param expression the expression to evaluate.
78 * @return true/false
79 */
80 public static boolean isOclIsKindOf(Object expression)
81 {
82 return TranslationUtils.deleteWhitespace(expression).matches(OCLFeatures.OCL_IS_KIND_OF);
83 }
84
85 /**
86 * Indicates if this <code>expression</code> is an OCL feature (that is it
87 * matches one of the features defined within this class).
88 *
89 * @param expression the expression to match.
90 * @return true/false
91 */
92 public static boolean isOclFeature(Object expression)
93 {
94 return TranslationUtils.deleteWhitespace(expression).matches(ALL_PATTERNS);
95 }
96
97 /**
98 * Represents the <em>self</em> keyword in OCL.
99 */
100 private static final String SELF = "self";
101
102 /**
103 * Indicates if this <code>expression</code> is an instance of the
104 * <em>self</em> key word.
105 *
106 * @param expression the expression to check.
107 * @return true/false
108 */
109 public static boolean isSelf(Object expression)
110 {
111 return TranslationUtils.deleteWhitespace(expression).matches(SELF);
112 }
113 }