< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java

Print this page

  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;

 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 

1308 
1309         public boolean isPermittedExplicit = false;
1310 
1311         private record PermittedClassWithPos(Symbol permittedClass, int pos) {}
1312 
1313         public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
1314             super(TYP, flags, name, type, owner);
1315             this.members_field = null;
1316             this.fullname = formFullName(name, owner);
1317             this.flatname = formFlatName(name, owner);
1318             this.sourcefile = null;
1319             this.classfile = null;
1320             this.annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
1321             this.permitted = new ArrayList<>();
1322         }
1323 
1324         public ClassSymbol(long flags, Name name, Symbol owner) {
1325             this(
1326                 flags,
1327                 name,
1328                 new ClassType(Type.noType, null, null),
1329                 owner);
1330             this.type.tsym = this;
1331         }
1332 
1333         public void addPermittedSubclass(ClassSymbol csym, int pos) {
1334             Assert.check(!isPermittedExplicit);
1335             // we need to insert at the right pos
1336             PermittedClassWithPos element = new PermittedClassWithPos(csym, pos);
1337             int index = Collections.binarySearch(permitted, element, java.util.Comparator.comparing(PermittedClassWithPos::pos));
1338             if (index < 0) {
1339                 index = -index - 1;
1340             }
1341             permitted.add(index, element);
1342         }
1343 
1344         public boolean isPermittedSubclass(Symbol csym) {
1345             for (PermittedClassWithPos permittedClassWithPos : permitted) {
1346                 if (permittedClassWithPos.permittedClass.equals(csym)) {
1347                     return true;
1348                 }

  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;

 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 isInterface() {
 407         return (flags_field & INTERFACE) != 0;
 408     }
 409 
 410     public boolean isAbstract() {
 411         return (flags_field & ABSTRACT) != 0;
 412     }
 413 
 414     public boolean isPrivate() {
 415         return (flags_field & Flags.AccessFlags) == PRIVATE;
 416     }
 417 
 418     public boolean isValueClass() {
 419         return (flags_field & VALUE_CLASS) != 0;
 420     }
 421 
 422     public boolean isIdentityClass() {
 423         return !isInterface() && (flags_field & IDENTITY_TYPE) != 0;
 424     }
 425 
 426     public boolean isPublic() {
 427         return (flags_field & Flags.AccessFlags) == PUBLIC;
 428     }
 429 
 430     public boolean isEnum() {
 431         return (flags() & ENUM) != 0;
 432     }
 433 
 434     public boolean isSealed() {
 435         return (flags_field & SEALED) != 0;
 436     }
 437 
 438     public boolean isNonSealed() {
 439         return (flags_field & NON_SEALED) != 0;
 440     }
 441 
 442     public boolean isFinal() {
 443         return (flags_field & FINAL) != 0;
 444     }
 445 

1315 
1316         public boolean isPermittedExplicit = false;
1317 
1318         private record PermittedClassWithPos(Symbol permittedClass, int pos) {}
1319 
1320         public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
1321             super(TYP, flags, name, type, owner);
1322             this.members_field = null;
1323             this.fullname = formFullName(name, owner);
1324             this.flatname = formFlatName(name, owner);
1325             this.sourcefile = null;
1326             this.classfile = null;
1327             this.annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
1328             this.permitted = new ArrayList<>();
1329         }
1330 
1331         public ClassSymbol(long flags, Name name, Symbol owner) {
1332             this(
1333                 flags,
1334                 name,
1335                 new ClassType(Type.noType, null, null, List.nil()),
1336                 owner);
1337             this.type.tsym = this;
1338         }
1339 
1340         public void addPermittedSubclass(ClassSymbol csym, int pos) {
1341             Assert.check(!isPermittedExplicit);
1342             // we need to insert at the right pos
1343             PermittedClassWithPos element = new PermittedClassWithPos(csym, pos);
1344             int index = Collections.binarySearch(permitted, element, java.util.Comparator.comparing(PermittedClassWithPos::pos));
1345             if (index < 0) {
1346                 index = -index - 1;
1347             }
1348             permitted.add(index, element);
1349         }
1350 
1351         public boolean isPermittedSubclass(Symbol csym) {
1352             for (PermittedClassWithPos permittedClassWithPos : permitted) {
1353                 if (permittedClassWithPos.permittedClass.equals(csym)) {
1354                     return true;
1355                 }
< prev index next >