< prev index next >

make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java

Print this page

 331                     jos.write(fd.fileData);
 332                 }
 333             }
 334         }
 335     }
 336 
 337     private static final String PREVIEW_FEATURE_ANNOTATION_OLD =
 338             "Ljdk/internal/PreviewFeature;";
 339     private static final String PREVIEW_FEATURE_ANNOTATION_NEW =
 340             "Ljdk/internal/javac/PreviewFeature;";
 341     private static final String PREVIEW_FEATURE_ANNOTATION_INTERNAL =
 342             "Ljdk/internal/PreviewFeature+Annotation;";
 343     private static final String RESTRICTED_ANNOTATION =
 344             "Ljdk/internal/javac/Restricted;";
 345     private static final String RESTRICTED_ANNOTATION_INTERNAL =
 346             "Ljdk/internal/javac/Restricted+Annotation;";
 347     private static final String VALUE_BASED_ANNOTATION =
 348             "Ljdk/internal/ValueBased;";
 349     private static final String VALUE_BASED_ANNOTATION_INTERNAL =
 350             "Ljdk/internal/ValueBased+Annotation;";




 351     public static final Set<String> HARDCODED_ANNOTATIONS = new HashSet<>(
 352             List.of("Ljdk/Profile+Annotation;",
 353                     "Lsun/Proprietary+Annotation;",
 354                     PREVIEW_FEATURE_ANNOTATION_OLD,
 355                     PREVIEW_FEATURE_ANNOTATION_NEW,
 356                     VALUE_BASED_ANNOTATION,

 357                     RESTRICTED_ANNOTATION));
 358 
 359     private void stripNonExistentAnnotations(LoadDescriptions data) {
 360         Set<String> allClasses = data.classes.name2Class.keySet();
 361         data.modules.values().forEach(mod -> {
 362             stripNonExistentAnnotations(allClasses, mod.header);
 363         });
 364         data.classes.classes.forEach(clazz -> {
 365             stripNonExistentAnnotations(allClasses, clazz.header);
 366             stripNonExistentAnnotations(allClasses, clazz.fields);
 367             stripNonExistentAnnotations(allClasses, clazz.methods);
 368         });
 369     }
 370 
 371     private void stripNonExistentAnnotations(Set<String> allClasses, Iterable<? extends FeatureDescription> descs) {
 372         descs.forEach(d -> stripNonExistentAnnotations(allClasses, d));
 373     }
 374 
 375     private void stripNonExistentAnnotations(Set<String> allClasses, FeatureDescription d) {
 376         stripNonExistentAnnotations(allClasses, d.classAnnotations);

1235             //the non-public PreviewFeature annotation will not be available in ct.sym,
1236             //replace with purely synthetic javac-internal annotation:
1237             annotationType = PREVIEW_FEATURE_ANNOTATION_INTERNAL;
1238         }
1239 
1240         if (PREVIEW_FEATURE_ANNOTATION_OLD.equals(annotationType)) {
1241             //the non-public PreviewFeature annotation will not be available in ct.sym,
1242             //replace with purely synthetic javac-internal annotation:
1243             annotationType = PREVIEW_FEATURE_ANNOTATION_INTERNAL;
1244             values = new HashMap<>(values);
1245             Boolean essentialAPI = (Boolean) values.remove("essentialAPI");
1246             values.put("reflective", essentialAPI != null && !essentialAPI);
1247         }
1248 
1249         if (VALUE_BASED_ANNOTATION.equals(annotationType)) {
1250             //the non-public ValueBased annotation will not be available in ct.sym,
1251             //replace with purely synthetic javac-internal annotation:
1252             annotationType = VALUE_BASED_ANNOTATION_INTERNAL;
1253         }
1254 






1255         if (RESTRICTED_ANNOTATION.equals(annotationType)) {
1256             //the non-public Restricted annotation will not be available in ct.sym,
1257             //replace with purely synthetic javac-internal annotation:
1258             annotationType = RESTRICTED_ANNOTATION_INTERNAL;
1259         }
1260 
1261         return new Annotation(null,
1262                               addString(constantPool, annotationType),
1263                               createElementPairs(constantPool, values));
1264     }
1265 
1266     private element_value_pair[] createElementPairs(List<CPInfo> constantPool, Map<String, Object> annotationAttributes) {
1267         element_value_pair[] pairs = new element_value_pair[annotationAttributes.size()];
1268         int i = 0;
1269 
1270         for (Entry<String, Object> e : annotationAttributes.entrySet()) {
1271             int elementNameString = addString(constantPool, e.getKey());
1272             element_value value = createAttributeValue(constantPool, e.getValue());
1273             pairs[i++] = new element_value_pair(elementNameString, value);
1274         }

2568                 }
2569                 ((ClassHeaderDescription) feature).innerClasses = innerClasses;
2570                 break;
2571             case "RuntimeInvisibleAnnotations":
2572                 feature.classAnnotations = annotations2Description(cf.constant_pool, attr);
2573                 break;
2574             case "RuntimeVisibleAnnotations":
2575                 feature.runtimeAnnotations = annotations2Description(cf.constant_pool, attr);
2576                 break;
2577             case "Signature":
2578                 feature.signature = ((Signature_attribute) attr).getSignature(cf.constant_pool);
2579                 break;
2580             case "ConstantValue":
2581                 assert feature instanceof FieldDescription;
2582                 Object value = convertConstantValue(cf.constant_pool.get(((ConstantValue_attribute) attr).constantvalue_index), ((FieldDescription) feature).descriptor);
2583                 if (((FieldDescription) feature).descriptor.equals("C")) {
2584                     value = (char) (int) value;
2585                 }
2586                 ((FieldDescription) feature).constantValue = value;
2587                 break;

2588             case "SourceFile":
2589                 //ignore, not needed
2590                 break;
2591             case "BootstrapMethods":
2592                 //ignore, not needed
2593                 break;
2594             case "Code":
2595                 //ignore, not needed
2596                 break;
2597             case "EnclosingMethod":
2598                 return false;
2599             case "Synthetic":
2600                 break;
2601             case "RuntimeVisibleParameterAnnotations":
2602                 assert feature instanceof MethodDescription;
2603                 ((MethodDescription) feature).runtimeParameterAnnotations =
2604                         parameterAnnotations2Description(cf.constant_pool, attr);
2605                 break;
2606             case "RuntimeInvisibleParameterAnnotations":
2607                 assert feature instanceof MethodDescription;

 331                     jos.write(fd.fileData);
 332                 }
 333             }
 334         }
 335     }
 336 
 337     private static final String PREVIEW_FEATURE_ANNOTATION_OLD =
 338             "Ljdk/internal/PreviewFeature;";
 339     private static final String PREVIEW_FEATURE_ANNOTATION_NEW =
 340             "Ljdk/internal/javac/PreviewFeature;";
 341     private static final String PREVIEW_FEATURE_ANNOTATION_INTERNAL =
 342             "Ljdk/internal/PreviewFeature+Annotation;";
 343     private static final String RESTRICTED_ANNOTATION =
 344             "Ljdk/internal/javac/Restricted;";
 345     private static final String RESTRICTED_ANNOTATION_INTERNAL =
 346             "Ljdk/internal/javac/Restricted+Annotation;";
 347     private static final String VALUE_BASED_ANNOTATION =
 348             "Ljdk/internal/ValueBased;";
 349     private static final String VALUE_BASED_ANNOTATION_INTERNAL =
 350             "Ljdk/internal/ValueBased+Annotation;";
 351     private static final String MIGRATED_VALUE_CLASS_ANNOTATION =
 352             "Ljdk/internal/MigratedValueClass;";
 353     private static final String MIGRATED_VALUE_CLASS_ANNOTATION_INTERNAL =
 354             "Ljdk/internal/MigratedValueClass+Annotation;";
 355     public static final Set<String> HARDCODED_ANNOTATIONS = new HashSet<>(
 356             List.of("Ljdk/Profile+Annotation;",
 357                     "Lsun/Proprietary+Annotation;",
 358                     PREVIEW_FEATURE_ANNOTATION_OLD,
 359                     PREVIEW_FEATURE_ANNOTATION_NEW,
 360                     VALUE_BASED_ANNOTATION,
 361                     MIGRATED_VALUE_CLASS_ANNOTATION,
 362                     RESTRICTED_ANNOTATION));
 363 
 364     private void stripNonExistentAnnotations(LoadDescriptions data) {
 365         Set<String> allClasses = data.classes.name2Class.keySet();
 366         data.modules.values().forEach(mod -> {
 367             stripNonExistentAnnotations(allClasses, mod.header);
 368         });
 369         data.classes.classes.forEach(clazz -> {
 370             stripNonExistentAnnotations(allClasses, clazz.header);
 371             stripNonExistentAnnotations(allClasses, clazz.fields);
 372             stripNonExistentAnnotations(allClasses, clazz.methods);
 373         });
 374     }
 375 
 376     private void stripNonExistentAnnotations(Set<String> allClasses, Iterable<? extends FeatureDescription> descs) {
 377         descs.forEach(d -> stripNonExistentAnnotations(allClasses, d));
 378     }
 379 
 380     private void stripNonExistentAnnotations(Set<String> allClasses, FeatureDescription d) {
 381         stripNonExistentAnnotations(allClasses, d.classAnnotations);

1240             //the non-public PreviewFeature annotation will not be available in ct.sym,
1241             //replace with purely synthetic javac-internal annotation:
1242             annotationType = PREVIEW_FEATURE_ANNOTATION_INTERNAL;
1243         }
1244 
1245         if (PREVIEW_FEATURE_ANNOTATION_OLD.equals(annotationType)) {
1246             //the non-public PreviewFeature annotation will not be available in ct.sym,
1247             //replace with purely synthetic javac-internal annotation:
1248             annotationType = PREVIEW_FEATURE_ANNOTATION_INTERNAL;
1249             values = new HashMap<>(values);
1250             Boolean essentialAPI = (Boolean) values.remove("essentialAPI");
1251             values.put("reflective", essentialAPI != null && !essentialAPI);
1252         }
1253 
1254         if (VALUE_BASED_ANNOTATION.equals(annotationType)) {
1255             //the non-public ValueBased annotation will not be available in ct.sym,
1256             //replace with purely synthetic javac-internal annotation:
1257             annotationType = VALUE_BASED_ANNOTATION_INTERNAL;
1258         }
1259 
1260         if (MIGRATED_VALUE_CLASS_ANNOTATION.equals(annotationType)) {
1261             //the non-public MigratedValueClass annotation will not be available in ct.sym,
1262             //replace with purely synthetic javac-internal annotation:
1263             annotationType = MIGRATED_VALUE_CLASS_ANNOTATION_INTERNAL;
1264         }
1265 
1266         if (RESTRICTED_ANNOTATION.equals(annotationType)) {
1267             //the non-public Restricted annotation will not be available in ct.sym,
1268             //replace with purely synthetic javac-internal annotation:
1269             annotationType = RESTRICTED_ANNOTATION_INTERNAL;
1270         }
1271 
1272         return new Annotation(null,
1273                               addString(constantPool, annotationType),
1274                               createElementPairs(constantPool, values));
1275     }
1276 
1277     private element_value_pair[] createElementPairs(List<CPInfo> constantPool, Map<String, Object> annotationAttributes) {
1278         element_value_pair[] pairs = new element_value_pair[annotationAttributes.size()];
1279         int i = 0;
1280 
1281         for (Entry<String, Object> e : annotationAttributes.entrySet()) {
1282             int elementNameString = addString(constantPool, e.getKey());
1283             element_value value = createAttributeValue(constantPool, e.getValue());
1284             pairs[i++] = new element_value_pair(elementNameString, value);
1285         }

2579                 }
2580                 ((ClassHeaderDescription) feature).innerClasses = innerClasses;
2581                 break;
2582             case "RuntimeInvisibleAnnotations":
2583                 feature.classAnnotations = annotations2Description(cf.constant_pool, attr);
2584                 break;
2585             case "RuntimeVisibleAnnotations":
2586                 feature.runtimeAnnotations = annotations2Description(cf.constant_pool, attr);
2587                 break;
2588             case "Signature":
2589                 feature.signature = ((Signature_attribute) attr).getSignature(cf.constant_pool);
2590                 break;
2591             case "ConstantValue":
2592                 assert feature instanceof FieldDescription;
2593                 Object value = convertConstantValue(cf.constant_pool.get(((ConstantValue_attribute) attr).constantvalue_index), ((FieldDescription) feature).descriptor);
2594                 if (((FieldDescription) feature).descriptor.equals("C")) {
2595                     value = (char) (int) value;
2596                 }
2597                 ((FieldDescription) feature).constantValue = value;
2598                 break;
2599             case "Preload":
2600             case "SourceFile":
2601                 //ignore, not needed
2602                 break;
2603             case "BootstrapMethods":
2604                 //ignore, not needed
2605                 break;
2606             case "Code":
2607                 //ignore, not needed
2608                 break;
2609             case "EnclosingMethod":
2610                 return false;
2611             case "Synthetic":
2612                 break;
2613             case "RuntimeVisibleParameterAnnotations":
2614                 assert feature instanceof MethodDescription;
2615                 ((MethodDescription) feature).runtimeParameterAnnotations =
2616                         parameterAnnotations2Description(cf.constant_pool, attr);
2617                 break;
2618             case "RuntimeInvisibleParameterAnnotations":
2619                 assert feature instanceof MethodDescription;
< prev index next >