MCPcopy Create free account
hub / github.com/antlr/codebuff / ClassOwnership

Enum ClassOwnership

output/java_guava/1.4.18/Types.java:111–148  ·  view source on GitHub ↗

Decides what owner type to use for constructing ParameterizedType from a raw class.

Source from the content-addressed store, hash-verified

109 /** Decides what owner type to use for constructing {@link ParameterizedType} from a raw class. */
110
111 private enum ClassOwnership {
112 OWNED_BY_ENCLOSING_CLASS {
113 @Nullable
114 @Override
115 Class<?> getOwnerType(Class<?> rawType) {
116 return rawType.getEnclosingClass();
117 }
118 },
119
120 LOCAL_CLASS_HAS_NO_OWNER {
121 @Nullable
122 @Override
123 Class<?> getOwnerType(Class<?> rawType) {
124 if (rawType.isLocalClass()) {
125 return null;
126 } else {
127 return rawType.getEnclosingClass();
128 }
129 }
130 };
131
132@Nullable
133abstract Class<?> getOwnerType(Class<?> rawType);
134static final ClassOwnership JVM_BEHAVIOR = detectJvmBehavior();
135
136
137private static ClassOwnership detectJvmBehavior() {
138 class LocalClass<T> {}
139 Class<?> subclass = new LocalClass<String>() {}.getClass();
140 ParameterizedType parameterizedType = (ParameterizedType) subclass.getGenericSuperclass();
141 for (ClassOwnership behavior : ClassOwnership.values()) {
142 if (behavior.getOwnerType(LocalClass.class) == parameterizedType.getOwnerType()) {
143 return behavior;
144 }
145 }
146 throw new AssertionError();
147}
148 }
149
150 /**
151 * Returns a new {@link TypeVariable} that belongs to {@code declaration} with {@code name} and

Callers

nothing calls this directly

Calls 1

detectJvmBehaviorMethod · 0.95

Tested by

no test coverage detected