< prev index next >

src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ElementsTable.java

Print this page




1183         public String toString() {
1184             return moduleName == null ? packageName : moduleName + "/" + packageName;
1185         }
1186     }
1187 
1188     /**
1189      * A class which filters the access flags on classes, fields, methods, etc.
1190      *
1191      * @see javax.lang.model.element.Modifier
1192      */
1193 
1194     static class ModifierFilter {
1195         /**
1196          * The allowed ElementKind that can be stored.
1197          */
1198         static final EnumSet<ElementKind> ALLOWED_KINDS = EnumSet.of(ElementKind.METHOD,
1199                                                     ElementKind.CLASS,
1200                                                     ElementKind.PACKAGE,
1201                                                     ElementKind.MODULE);
1202 
1203         // all possible accesss levels allowed for each element
1204         private final EnumMap<ElementKind, EnumSet<AccessKind>> filterMap =
1205                 new EnumMap<>(ElementKind.class);
1206 
1207         // the specified access level for each element
1208         private final EnumMap<ElementKind, AccessKind> accessMap =
1209                 new EnumMap<>(ElementKind.class);
1210 
1211         /**
1212          * Constructor - Specify a filter.
1213          *
1214          * @param accessSet an Access filter.
1215          */
1216         ModifierFilter(Map<ToolOption, Object> opts) {
1217 
1218             AccessKind accessValue = null;
1219             for (ElementKind kind : ALLOWED_KINDS) {
1220                 switch (kind) {
1221                     case METHOD:
1222                         accessValue  = (AccessKind)opts.get(ToolOption.SHOW_MEMBERS);
1223                         break;


1268          */
1269         public boolean checkModifier(Element e) {
1270             Set<Modifier> modifiers = e.getModifiers();
1271             AccessKind fflag = AccessKind.PACKAGE;
1272             if (modifiers.contains(Modifier.PUBLIC)) {
1273                 fflag = AccessKind.PUBLIC;
1274             } else if (modifiers.contains(Modifier.PROTECTED)) {
1275                 fflag = AccessKind.PROTECTED;
1276             } else if (modifiers.contains(Modifier.PRIVATE)) {
1277                 fflag = AccessKind.PRIVATE;
1278             }
1279             EnumSet<AccessKind> filterSet = filterMap.get(getAllowedKind(e.getKind()));
1280             return filterSet.contains(fflag);
1281         }
1282 
1283         // convert a requested element kind to an allowed access kind
1284         private ElementKind getAllowedKind(ElementKind kind) {
1285             switch (kind) {
1286                 case CLASS: case METHOD: case MODULE: case PACKAGE:
1287                     return kind;
1288                 case ANNOTATION_TYPE: case ENUM: case INTERFACE:
1289                     return ElementKind.CLASS;
1290                 case CONSTRUCTOR: case ENUM_CONSTANT: case EXCEPTION_PARAMETER:
1291                 case FIELD: case INSTANCE_INIT: case LOCAL_VARIABLE: case PARAMETER:
1292                 case RESOURCE_VARIABLE: case STATIC_INIT: case TYPE_PARAMETER:
1293                     return ElementKind.METHOD;
1294                 default:
1295                     throw new AssertionError("unsupported kind: " + kind);
1296             }
1297         }
1298     } // end ModifierFilter
1299 }


1183         public String toString() {
1184             return moduleName == null ? packageName : moduleName + "/" + packageName;
1185         }
1186     }
1187 
1188     /**
1189      * A class which filters the access flags on classes, fields, methods, etc.
1190      *
1191      * @see javax.lang.model.element.Modifier
1192      */
1193 
1194     static class ModifierFilter {
1195         /**
1196          * The allowed ElementKind that can be stored.
1197          */
1198         static final EnumSet<ElementKind> ALLOWED_KINDS = EnumSet.of(ElementKind.METHOD,
1199                                                     ElementKind.CLASS,
1200                                                     ElementKind.PACKAGE,
1201                                                     ElementKind.MODULE);
1202 
1203         // all possible access levels allowed for each element
1204         private final EnumMap<ElementKind, EnumSet<AccessKind>> filterMap =
1205                 new EnumMap<>(ElementKind.class);
1206 
1207         // the specified access level for each element
1208         private final EnumMap<ElementKind, AccessKind> accessMap =
1209                 new EnumMap<>(ElementKind.class);
1210 
1211         /**
1212          * Constructor - Specify a filter.
1213          *
1214          * @param accessSet an Access filter.
1215          */
1216         ModifierFilter(Map<ToolOption, Object> opts) {
1217 
1218             AccessKind accessValue = null;
1219             for (ElementKind kind : ALLOWED_KINDS) {
1220                 switch (kind) {
1221                     case METHOD:
1222                         accessValue  = (AccessKind)opts.get(ToolOption.SHOW_MEMBERS);
1223                         break;


1268          */
1269         public boolean checkModifier(Element e) {
1270             Set<Modifier> modifiers = e.getModifiers();
1271             AccessKind fflag = AccessKind.PACKAGE;
1272             if (modifiers.contains(Modifier.PUBLIC)) {
1273                 fflag = AccessKind.PUBLIC;
1274             } else if (modifiers.contains(Modifier.PROTECTED)) {
1275                 fflag = AccessKind.PROTECTED;
1276             } else if (modifiers.contains(Modifier.PRIVATE)) {
1277                 fflag = AccessKind.PRIVATE;
1278             }
1279             EnumSet<AccessKind> filterSet = filterMap.get(getAllowedKind(e.getKind()));
1280             return filterSet.contains(fflag);
1281         }
1282 
1283         // convert a requested element kind to an allowed access kind
1284         private ElementKind getAllowedKind(ElementKind kind) {
1285             switch (kind) {
1286                 case CLASS: case METHOD: case MODULE: case PACKAGE:
1287                     return kind;
1288                 case RECORD: case ANNOTATION_TYPE: case ENUM: case INTERFACE:
1289                     return ElementKind.CLASS;
1290                 case CONSTRUCTOR: case ENUM_CONSTANT: case EXCEPTION_PARAMETER:
1291                 case FIELD: case INSTANCE_INIT: case LOCAL_VARIABLE: case PARAMETER:
1292                 case RESOURCE_VARIABLE: case STATIC_INIT: case TYPE_PARAMETER:
1293                     return ElementKind.METHOD;
1294                 default:
1295                     throw new AssertionError("unsupported kind: " + kind);
1296             }
1297         }
1298     } // end ModifierFilter
1299 }
< prev index next >