13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.javac.code;
27
28 import java.lang.annotation.Annotation;
29 import java.lang.annotation.Inherited;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.EnumSet;
33 import java.util.HashMap;
34 import java.util.Map;
35 import java.util.Set;
36 import java.util.concurrent.Callable;
37 import java.util.function.Supplier;
38 import java.util.function.Predicate;
39
40 import javax.lang.model.element.Element;
41 import javax.lang.model.element.ElementKind;
42 import javax.lang.model.element.ElementVisitor;
43 import javax.lang.model.element.ExecutableElement;
44 import javax.lang.model.element.Modifier;
45 import javax.lang.model.element.ModuleElement;
46 import javax.lang.model.element.NestingKind;
47 import javax.lang.model.element.PackageElement;
48 import javax.lang.model.element.RecordComponentElement;
49 import javax.lang.model.element.TypeElement;
50 import javax.lang.model.element.TypeParameterElement;
51 import javax.lang.model.element.VariableElement;
52 import javax.tools.JavaFileManager;
53 import javax.tools.JavaFileObject;
387 public boolean isDeprecatableViaAnnotation() {
388 switch (getKind()) {
389 case LOCAL_VARIABLE:
390 case PACKAGE:
391 case PARAMETER:
392 case RESOURCE_VARIABLE:
393 case EXCEPTION_PARAMETER:
394 return false;
395 default:
396 return true;
397 }
398 }
399
400 public boolean isStatic() {
401 return
402 (flags() & STATIC) != 0 ||
403 (owner.flags() & INTERFACE) != 0 && kind != MTH &&
404 name != name.table.names._this;
405 }
406
407 public boolean isInterface() {
408 return (flags() & INTERFACE) != 0;
409 }
410
411 public boolean isAbstract() {
412 return (flags_field & ABSTRACT) != 0;
413 }
414
415 public boolean isPrivate() {
416 return (flags_field & Flags.AccessFlags) == PRIVATE;
417 }
418
419 public boolean isPublic() {
420 return (flags_field & Flags.AccessFlags) == PUBLIC;
421 }
422
423 public boolean isEnum() {
424 return (flags() & ENUM) != 0;
425 }
426
427 public boolean isSealed() {
428 return (flags_field & SEALED) != 0;
429 }
430
431 public boolean isNonSealed() {
432 return (flags_field & NON_SEALED) != 0;
433 }
434
435 public boolean isFinal() {
436 return (flags_field & FINAL) != 0;
437 }
438
1324
1325 public boolean isPermittedExplicit = false;
1326
1327 private record PermittedClassWithPos(Symbol permittedClass, int pos) {}
1328
1329 public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
1330 super(TYP, flags, name, type, owner);
1331 this.members_field = null;
1332 this.fullname = formFullName(name, owner);
1333 this.flatname = formFlatName(name, owner);
1334 this.sourcefile = null;
1335 this.classfile = null;
1336 this.annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
1337 this.permitted = new ArrayList<>();
1338 }
1339
1340 public ClassSymbol(long flags, Name name, Symbol owner) {
1341 this(
1342 flags,
1343 name,
1344 new ClassType(Type.noType, null, null),
1345 owner);
1346 this.type.tsym = this;
1347 }
1348
1349 public void addPermittedSubclass(ClassSymbol csym, int pos) {
1350 Assert.check(!isPermittedExplicit);
1351 // we need to insert at the right pos
1352 PermittedClassWithPos element = new PermittedClassWithPos(csym, pos);
1353 int index = Collections.binarySearch(permitted, element, java.util.Comparator.comparing(PermittedClassWithPos::pos));
1354 if (index < 0) {
1355 index = -index - 1;
1356 }
1357 permitted.add(index, element);
1358 }
1359
1360 public boolean isPermittedSubclass(Symbol csym) {
1361 for (PermittedClassWithPos permittedClassWithPos : permitted) {
1362 if (permittedClassWithPos.permittedClass.equals(csym)) {
1363 return true;
1364 }
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.javac.code;
27
28 import java.lang.annotation.Annotation;
29 import java.lang.annotation.Inherited;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.EnumSet;
33 import java.util.Map;
34 import java.util.Set;
35 import java.util.concurrent.Callable;
36 import java.util.function.Supplier;
37 import java.util.function.Predicate;
38
39 import javax.lang.model.element.Element;
40 import javax.lang.model.element.ElementKind;
41 import javax.lang.model.element.ElementVisitor;
42 import javax.lang.model.element.ExecutableElement;
43 import javax.lang.model.element.Modifier;
44 import javax.lang.model.element.ModuleElement;
45 import javax.lang.model.element.NestingKind;
46 import javax.lang.model.element.PackageElement;
47 import javax.lang.model.element.RecordComponentElement;
48 import javax.lang.model.element.TypeElement;
49 import javax.lang.model.element.TypeParameterElement;
50 import javax.lang.model.element.VariableElement;
51 import javax.tools.JavaFileManager;
52 import javax.tools.JavaFileObject;
386 public boolean isDeprecatableViaAnnotation() {
387 switch (getKind()) {
388 case LOCAL_VARIABLE:
389 case PACKAGE:
390 case PARAMETER:
391 case RESOURCE_VARIABLE:
392 case EXCEPTION_PARAMETER:
393 return false;
394 default:
395 return true;
396 }
397 }
398
399 public boolean isStatic() {
400 return
401 (flags() & STATIC) != 0 ||
402 (owner.flags() & INTERFACE) != 0 && kind != MTH &&
403 name != name.table.names._this;
404 }
405
406 public boolean isStrict() {
407 return (flags() & STRICT) != 0;
408 }
409
410 public boolean isInterface() {
411 return (flags_field & INTERFACE) != 0;
412 }
413
414 public boolean isAbstract() {
415 return (flags_field & ABSTRACT) != 0;
416 }
417
418 public boolean isPrivate() {
419 return (flags_field & Flags.AccessFlags) == PRIVATE;
420 }
421
422 public boolean isValueClass() {
423 return (flags_field & VALUE_CLASS) != 0;
424 }
425
426 public boolean isIdentityClass() {
427 return !isInterface() && (flags_field & IDENTITY_TYPE) != 0;
428 }
429
430 public boolean isPublic() {
431 return (flags_field & Flags.AccessFlags) == PUBLIC;
432 }
433
434 public boolean isEnum() {
435 return (flags() & ENUM) != 0;
436 }
437
438 public boolean isSealed() {
439 return (flags_field & SEALED) != 0;
440 }
441
442 public boolean isNonSealed() {
443 return (flags_field & NON_SEALED) != 0;
444 }
445
446 public boolean isFinal() {
447 return (flags_field & FINAL) != 0;
448 }
449
1335
1336 public boolean isPermittedExplicit = false;
1337
1338 private record PermittedClassWithPos(Symbol permittedClass, int pos) {}
1339
1340 public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
1341 super(TYP, flags, name, type, owner);
1342 this.members_field = null;
1343 this.fullname = formFullName(name, owner);
1344 this.flatname = formFlatName(name, owner);
1345 this.sourcefile = null;
1346 this.classfile = null;
1347 this.annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
1348 this.permitted = new ArrayList<>();
1349 }
1350
1351 public ClassSymbol(long flags, Name name, Symbol owner) {
1352 this(
1353 flags,
1354 name,
1355 new ClassType(Type.noType, null, null, List.nil()),
1356 owner);
1357 this.type.tsym = this;
1358 }
1359
1360 public void addPermittedSubclass(ClassSymbol csym, int pos) {
1361 Assert.check(!isPermittedExplicit);
1362 // we need to insert at the right pos
1363 PermittedClassWithPos element = new PermittedClassWithPos(csym, pos);
1364 int index = Collections.binarySearch(permitted, element, java.util.Comparator.comparing(PermittedClassWithPos::pos));
1365 if (index < 0) {
1366 index = -index - 1;
1367 }
1368 permitted.add(index, element);
1369 }
1370
1371 public boolean isPermittedSubclass(Symbol csym) {
1372 for (PermittedClassWithPos permittedClassWithPos : permitted) {
1373 if (permittedClassWithPos.permittedClass.equals(csym)) {
1374 return true;
1375 }
|