< prev index next >

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

Print this page

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




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

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

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






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

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

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

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

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

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