< 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 

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;

 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 

1331 
1332         public boolean isPermittedExplicit = false;
1333 
1334         private record PermittedClassWithPos(Symbol permittedClass, int pos) {}
1335 
1336         public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
1337             super(TYP, flags, name, type, owner);
1338             this.members_field = null;
1339             this.fullname = formFullName(name, owner);
1340             this.flatname = formFlatName(name, owner);
1341             this.sourcefile = null;
1342             this.classfile = null;
1343             this.annotationTypeMetadata = AnnotationTypeMetadata.notAnAnnotationType();
1344             this.permitted = new ArrayList<>();
1345         }
1346 
1347         public ClassSymbol(long flags, Name name, Symbol owner) {
1348             this(
1349                 flags,
1350                 name,
1351                 new ClassType(Type.noType, null, null, List.nil()),
1352                 owner);
1353             this.type.tsym = this;
1354         }
1355 
1356         public void addPermittedSubclass(ClassSymbol csym, int pos) {
1357             Assert.check(!isPermittedExplicit);
1358             // we need to insert at the right pos
1359             PermittedClassWithPos element = new PermittedClassWithPos(csym, pos);
1360             int index = Collections.binarySearch(permitted, element, java.util.Comparator.comparing(PermittedClassWithPos::pos));
1361             if (index < 0) {
1362                 index = -index - 1;
1363             }
1364             permitted.add(index, element);
1365         }
1366 
1367         public boolean isPermittedSubclass(Symbol csym) {
1368             for (PermittedClassWithPos permittedClassWithPos : permitted) {
1369                 if (permittedClassWithPos.permittedClass.equals(csym)) {
1370                     return true;
1371                 }
< prev index next >