01: package org.andromda.translation.ocl.syntax;
02:
03: import org.andromda.core.translation.TranslationUtils;
04:
05: /**
06: * Contains the patterns matching constructs within the OCL language.
07: *
08: * @author Chad Brandon
09: */
10: public class OCLPatterns {
11: /**
12: * Matches on the pattern of a scope path (i.e. java :: lang :: Integer).
13: */
14: static final String SCOPE_PATH = "[\\w+|::]+";
15:
16: /**
17: * Matches on the pattern of a navigational path (i.e. person.name.first)
18: */
19: static final String NAVIGATIONAL_PATH = "[\\w*[\\.]*]+";
20:
21: /**
22: * Indicates if this <code>expression</code> is an operation.
23: *
24: * @param expression the expression to match.
25: * @return true/false
26: */
27: public static boolean isOperation(Object expression) {
28: return TranslationUtils.deleteWhitespace(expression).matches(
29: OPERATION);
30: }
31:
32: private static final String OPERATION = ".+\\(.*\\).*";
33:
34: /**
35: * Indicates if this <code>expression</code> is a collection (->) operation call.
36: *
37: * @param expression the expression to match.
38: * @return true/false
39: */
40: public static boolean isCollectionOperationCall(Object expression) {
41: return TranslationUtils.deleteWhitespace(expression).matches(
42: COLLECTION_CALL);
43: }
44:
45: private static final String COLLECTION_CALL = ".+->.+";
46:
47: /**
48: * Indicates if this <code>expression</code> is a collection operation result navigational path
49: * (->someOperation().some.path)
50: *
51: * @param expression the expression to match.
52: * @return true/false
53: */
54: public static boolean isCollectionOperationResultNavigationalPath(
55: Object expression) {
56: return TranslationUtils.deleteWhitespace(expression).matches(
57: COLLECTION_CALL_RESULT_NAVIGATIONAL_PATH);
58: }
59:
60: /**
61: * Indicates if this <code>expression</code> is a navigational path
62: * (some.path)
63: *
64: * @param expression the expression to match.
65: * @return true/false
66: */
67: public static boolean isNavigationalPath(Object expression) {
68: return TranslationUtils.deleteWhitespace(expression).matches(
69: NAVIGATIONAL_PATH);
70: }
71:
72: private static final String COLLECTION_CALL_RESULT_NAVIGATIONAL_PATH = ".+->"
73: + OPERATION + NAVIGATIONAL_PATH;
74:
75: /**
76: * Pattern for <em>and</em> and <em>or</em> expression matching.
77: */
78: private static final String AND_OR_OR_OPERATOR = "or\\s+.*|and\\s+.*";
79:
80: /**
81: * Indicates if this <code>expression</code> is an <em>and</em>
82: * or <em>or</em> expression (or some.path, and some.path, etc)
83: *
84: * @param expression the expression to match.
85: * @return true/false
86: */
87: public static boolean isAndOrOrExpression(Object expression) {
88: return TranslationUtils.trimToEmpty(expression).matches(
89: AND_OR_OR_OPERATOR);
90: }
91: }
|