// // Terminal Buffer check // /* * the following code is adapted from real DJ code found at: * http://www.ccs.neu.edu/research/demeter/DemeterJava/use/latest-demjava/ * aplib/cd/utils.beh */ Opt_labeled_term { {{ private static String builtinTypes[] = { "boolean", "char", "byte", "short", "int", "long", "float", "double" }; private static String terminalClasses[] = { // from java.lang.*: "Boolean", "Character", "Integer", "Long", "Float", "Double", "Number", "String", "StringBuffer", // from demeter.*: "Ident", "Text", "Line", "Word" }; }} boolean isBuiltinType() {{ String s = get_class_name(); for (int i = 0; i < builtinTypes.length; i++) { if (builtinTypes[i].equals(s)) return true; } return false; }} boolean isTerminalClass() {{ String s = get_class_name(); for (int i = 0; i < terminalClasses.length; i++) { if (terminalClasses[i].equals(s)) return true; } return false; }} boolean isKnownTerminal() {{ return isBuiltinType() || isTerminalClass(); }} } /* * end of adapted DJ code */ Adjacency { /* * returns true if the class contains a terminal class */ boolean contains_terminal() to Opt_labeled_term { {{ boolean b; }} init {{ b = false; }} before Opt_labeled_term {{ if (host.isKnownTerminal()) b = true; }} after Adjacency {{ return_val = b; }} } /* * counts the number of constructs in a class */ int count_construct() to Opt_labeled_term { {{ int i; }} init {{ i = 0; }} before Opt_labeled_term {{ i++; }} after Adjacency {{ return_val = i; }} } } Cd_graph { /* * if a class contains a terminal class, and has more than * one construct, it violates terminal buffer rule */ void terminal_check() to Adjacency { before Adjacency {{ if ((host.contains_terminal())&& (host.count_construct() > 1)) System.out.println("WARNING: Class " + host.get_source_name() + " violates terminal buffer rule."); }} } }