MCPcopy Create free account
hub / github.com/apache/groovy / canMean

Method canMean

src/main/java/org/codehaus/groovy/syntax/Types.java:1018–1064  ·  view source on GitHub ↗

Determines if a type can be interpreted as another type. This is orthogonal to #ofType(int, int) and is used for semantic flexibility (e.g., an identifier can be viewed as a class name). @param actual the actual type being checked @param preferred the desired interpretation @return {@code t

(int actual, int preferred)

Source from the content-addressed store, hash-verified

1016 * @return {@code true} if the actual type can be reinterpreted as the preferred type
1017 */
1018 public static boolean canMean(int actual, int preferred) {
1019
1020 if (actual == preferred) {
1021 return true;
1022 }
1023
1024 switch (preferred) {
1025
1026 case SYNTH_PARAMETER_DECLARATION:
1027 case IDENTIFIER:
1028 switch (actual) {
1029 case IDENTIFIER:
1030 case KEYWORD_DEF:
1031 case KEYWORD_DEFMACRO:
1032 case KEYWORD_CLASS:
1033 case KEYWORD_INTERFACE:
1034 case KEYWORD_MIXIN:
1035 return true;
1036 }
1037 break;
1038
1039 case SYNTH_CLASS:
1040 case SYNTH_INTERFACE:
1041 case SYNTH_MIXIN:
1042 case SYNTH_METHOD:
1043 case SYNTH_PROPERTY:
1044
1045 case SYNTH_VARIABLE_DECLARATION:
1046 return actual == IDENTIFIER;
1047
1048 case SYNTH_LIST:
1049 case SYNTH_MAP:
1050 return actual == LEFT_SQUARE_BRACKET;
1051
1052 case SYNTH_CAST:
1053 return actual == LEFT_PARENTHESIS;
1054
1055 case SYNTH_BLOCK:
1056 case SYNTH_CLOSURE:
1057 return actual == LEFT_CURLY_BRACE;
1058
1059 case SYNTH_LABEL:
1060 return actual == COLON;
1061 }
1062
1063 return false;
1064 }
1065
1066 /**
1067 * Converts an operator node's meaning to a prefix operator variant.

Callers 1

canMeanMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected