< prev index next >

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

Print this page

 287                     jos.write(fd.fileData);
 288                 }
 289             }
 290         }
 291     }
 292 
 293     private static final String PREVIEW_FEATURE_ANNOTATION_OLD =
 294             "Ljdk/internal/PreviewFeature;";
 295     private static final String PREVIEW_FEATURE_ANNOTATION_NEW =
 296             "Ljdk/internal/javac/PreviewFeature;";
 297     private static final String PREVIEW_FEATURE_ANNOTATION_INTERNAL =
 298             "Ljdk/internal/PreviewFeature+Annotation;";
 299     private static final String RESTRICTED_ANNOTATION =
 300             "Ljdk/internal/javac/Restricted;";
 301     private static final String RESTRICTED_ANNOTATION_INTERNAL =
 302             "Ljdk/internal/javac/Restricted+Annotation;";
 303     private static final String VALUE_BASED_ANNOTATION =
 304             "Ljdk/internal/ValueBased;";
 305     private static final String VALUE_BASED_ANNOTATION_INTERNAL =
 306             "Ljdk/internal/ValueBased+Annotation;";




 307     public static final Set<String> HARDCODED_ANNOTATIONS = new HashSet<>(
 308             List.of("Ljdk/Profile+Annotation;",
 309                     "Lsun/Proprietary+Annotation;",
 310                     PREVIEW_FEATURE_ANNOTATION_OLD,
 311                     PREVIEW_FEATURE_ANNOTATION_NEW,
 312                     VALUE_BASED_ANNOTATION,

 313                     RESTRICTED_ANNOTATION));
 314 
 315     private void stripNonExistentAnnotations(LoadDescriptions data) {
 316         Set<String> allClasses = data.classes.name2Class.keySet();
 317         data.modules.values().forEach(mod -> {
 318             stripNonExistentAnnotations(allClasses, mod.header);
 319         });
 320         data.classes.classes.forEach(clazz -> {
 321             stripNonExistentAnnotations(allClasses, clazz.header);
 322             stripNonExistentAnnotations(allClasses, clazz.fields);
 323             stripNonExistentAnnotations(allClasses, clazz.methods);
 324         });
 325     }
 326 
 327     private void stripNonExistentAnnotations(Set<String> allClasses, Iterable<? extends FeatureDescription> descs) {
 328         descs.forEach(d -> stripNonExistentAnnotations(allClasses, d));
 329     }
 330 
 331     private void stripNonExistentAnnotations(Set<String> allClasses, FeatureDescription d) {
 332         stripNonExistentAnnotations(allClasses, d.classAnnotations);

1004             //the non-public PreviewFeature annotation will not be available in ct.sym,
1005             //replace with purely synthetic javac-internal annotation:
1006             annotationType = PREVIEW_FEATURE_ANNOTATION_INTERNAL;
1007         }
1008 
1009         if (PREVIEW_FEATURE_ANNOTATION_OLD.equals(annotationType)) {
1010             //the non-public PreviewFeature annotation will not be available in ct.sym,
1011             //replace with purely synthetic javac-internal annotation:
1012             annotationType = PREVIEW_FEATURE_ANNOTATION_INTERNAL;
1013             values = new HashMap<>(values);
1014             Boolean essentialAPI = (Boolean) values.remove("essentialAPI");
1015             values.put("reflective", essentialAPI != null && !essentialAPI);
1016         }
1017 
1018         if (VALUE_BASED_ANNOTATION.equals(annotationType)) {
1019             //the non-public ValueBased annotation will not be available in ct.sym,
1020             //replace with purely synthetic javac-internal annotation:
1021             annotationType = VALUE_BASED_ANNOTATION_INTERNAL;
1022         }
1023 






1024         if (RESTRICTED_ANNOTATION.equals(annotationType)) {
1025             //the non-public Restricted annotation will not be available in ct.sym,
1026             //replace with purely synthetic javac-internal annotation:
1027             annotationType = RESTRICTED_ANNOTATION_INTERNAL;
1028         }
1029 
1030         return Annotation.of(ClassDesc.ofDescriptor(annotationType),
1031                 createElementPairs(values));
1032     }
1033 
1034     private List<AnnotationElement> createElementPairs(Map<String, Object> annotationAttributes) {
1035         return annotationAttributes.entrySet().stream()
1036                 .map(e -> AnnotationElement.of(e.getKey(), createAttributeValue(e.getValue())))
1037                 .collect(Collectors.toList());
1038     }
1039 
1040     private AnnotationValue createAttributeValue(Object value) {
1041         return switch (value) {
1042             case Boolean v -> AnnotationValue.ofBoolean(v);
1043             case Byte v -> AnnotationValue.ofByte(v);

 287                     jos.write(fd.fileData);
 288                 }
 289             }
 290         }
 291     }
 292 
 293     private static final String PREVIEW_FEATURE_ANNOTATION_OLD =
 294             "Ljdk/internal/PreviewFeature;";
 295     private static final String PREVIEW_FEATURE_ANNOTATION_NEW =
 296             "Ljdk/internal/javac/PreviewFeature;";
 297     private static final String PREVIEW_FEATURE_ANNOTATION_INTERNAL =
 298             "Ljdk/internal/PreviewFeature+Annotation;";
 299     private static final String RESTRICTED_ANNOTATION =
 300             "Ljdk/internal/javac/Restricted;";
 301     private static final String RESTRICTED_ANNOTATION_INTERNAL =
 302             "Ljdk/internal/javac/Restricted+Annotation;";
 303     private static final String VALUE_BASED_ANNOTATION =
 304             "Ljdk/internal/ValueBased;";
 305     private static final String VALUE_BASED_ANNOTATION_INTERNAL =
 306             "Ljdk/internal/ValueBased+Annotation;";
 307     private static final String MIGRATED_VALUE_CLASS_ANNOTATION =
 308             "Ljdk/internal/MigratedValueClass;";
 309     private static final String MIGRATED_VALUE_CLASS_ANNOTATION_INTERNAL =
 310             "Ljdk/internal/MigratedValueClass+Annotation;";
 311     public static final Set<String> HARDCODED_ANNOTATIONS = new HashSet<>(
 312             List.of("Ljdk/Profile+Annotation;",
 313                     "Lsun/Proprietary+Annotation;",
 314                     PREVIEW_FEATURE_ANNOTATION_OLD,
 315                     PREVIEW_FEATURE_ANNOTATION_NEW,
 316                     VALUE_BASED_ANNOTATION,
 317                     MIGRATED_VALUE_CLASS_ANNOTATION,
 318                     RESTRICTED_ANNOTATION));
 319 
 320     private void stripNonExistentAnnotations(LoadDescriptions data) {
 321         Set<String> allClasses = data.classes.name2Class.keySet();
 322         data.modules.values().forEach(mod -> {
 323             stripNonExistentAnnotations(allClasses, mod.header);
 324         });
 325         data.classes.classes.forEach(clazz -> {
 326             stripNonExistentAnnotations(allClasses, clazz.header);
 327             stripNonExistentAnnotations(allClasses, clazz.fields);
 328             stripNonExistentAnnotations(allClasses, clazz.methods);
 329         });
 330     }
 331 
 332     private void stripNonExistentAnnotations(Set<String> allClasses, Iterable<? extends FeatureDescription> descs) {
 333         descs.forEach(d -> stripNonExistentAnnotations(allClasses, d));
 334     }
 335 
 336     private void stripNonExistentAnnotations(Set<String> allClasses, FeatureDescription d) {
 337         stripNonExistentAnnotations(allClasses, d.classAnnotations);

1009             //the non-public PreviewFeature annotation will not be available in ct.sym,
1010             //replace with purely synthetic javac-internal annotation:
1011             annotationType = PREVIEW_FEATURE_ANNOTATION_INTERNAL;
1012         }
1013 
1014         if (PREVIEW_FEATURE_ANNOTATION_OLD.equals(annotationType)) {
1015             //the non-public PreviewFeature annotation will not be available in ct.sym,
1016             //replace with purely synthetic javac-internal annotation:
1017             annotationType = PREVIEW_FEATURE_ANNOTATION_INTERNAL;
1018             values = new HashMap<>(values);
1019             Boolean essentialAPI = (Boolean) values.remove("essentialAPI");
1020             values.put("reflective", essentialAPI != null && !essentialAPI);
1021         }
1022 
1023         if (VALUE_BASED_ANNOTATION.equals(annotationType)) {
1024             //the non-public ValueBased annotation will not be available in ct.sym,
1025             //replace with purely synthetic javac-internal annotation:
1026             annotationType = VALUE_BASED_ANNOTATION_INTERNAL;
1027         }
1028 
1029         if (MIGRATED_VALUE_CLASS_ANNOTATION.equals(annotationType)) {
1030             //the non-public MigratedValueClass annotation will not be available in ct.sym,
1031             //replace with purely synthetic javac-internal annotation:
1032             annotationType = MIGRATED_VALUE_CLASS_ANNOTATION_INTERNAL;
1033         }
1034 
1035         if (RESTRICTED_ANNOTATION.equals(annotationType)) {
1036             //the non-public Restricted annotation will not be available in ct.sym,
1037             //replace with purely synthetic javac-internal annotation:
1038             annotationType = RESTRICTED_ANNOTATION_INTERNAL;
1039         }
1040 
1041         return Annotation.of(ClassDesc.ofDescriptor(annotationType),
1042                 createElementPairs(values));
1043     }
1044 
1045     private List<AnnotationElement> createElementPairs(Map<String, Object> annotationAttributes) {
1046         return annotationAttributes.entrySet().stream()
1047                 .map(e -> AnnotationElement.of(e.getKey(), createAttributeValue(e.getValue())))
1048                 .collect(Collectors.toList());
1049     }
1050 
1051     private AnnotationValue createAttributeValue(Object value) {
1052         return switch (value) {
1053             case Boolean v -> AnnotationValue.ofBoolean(v);
1054             case Byte v -> AnnotationValue.ofByte(v);
< prev index next >