Lines 53-58
Link Here
|
53 |
import org.eclipse.jdt.internal.compiler.impl.Constant; |
53 |
import org.eclipse.jdt.internal.compiler.impl.Constant; |
54 |
import org.eclipse.jdt.internal.compiler.impl.StringConstant; |
54 |
import org.eclipse.jdt.internal.compiler.impl.StringConstant; |
55 |
import org.eclipse.jdt.internal.compiler.lookup.Binding; |
55 |
import org.eclipse.jdt.internal.compiler.lookup.Binding; |
|
|
56 |
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; |
56 |
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; |
57 |
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; |
57 |
import org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding; |
58 |
import org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding; |
58 |
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; |
59 |
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; |
Lines 324-330
Link Here
|
324 |
if (typeDeclaration != null) { |
325 |
if (typeDeclaration != null) { |
325 |
final Annotation[] annotations = typeDeclaration.annotations; |
326 |
final Annotation[] annotations = typeDeclaration.annotations; |
326 |
if (annotations != null) { |
327 |
if (annotations != null) { |
327 |
attributesNumber += generateRuntimeAnnotations(annotations); |
328 |
attributesNumber += generateRuntimeAnnotations(annotations, 0); |
328 |
} |
329 |
} |
329 |
} |
330 |
} |
330 |
} |
331 |
} |
Lines 413-419
Link Here
|
413 |
if (fieldDeclaration != null) { |
414 |
if (fieldDeclaration != null) { |
414 |
Annotation[] annotations = fieldDeclaration.annotations; |
415 |
Annotation[] annotations = fieldDeclaration.annotations; |
415 |
if (annotations != null) { |
416 |
if (annotations != null) { |
416 |
attributesNumber += generateRuntimeAnnotations(annotations); |
417 |
attributesNumber += generateRuntimeAnnotations(annotations, 0); |
417 |
} |
418 |
} |
418 |
} |
419 |
} |
419 |
} |
420 |
} |
Lines 2683-2690
Link Here
|
2683 |
AbstractMethodDeclaration methodDeclaration = methodBinding.sourceMethod(); |
2684 |
AbstractMethodDeclaration methodDeclaration = methodBinding.sourceMethod(); |
2684 |
if (methodDeclaration != null) { |
2685 |
if (methodDeclaration != null) { |
2685 |
Annotation[] annotations = methodDeclaration.annotations; |
2686 |
Annotation[] annotations = methodDeclaration.annotations; |
2686 |
if (annotations != null) { |
2687 |
int modifiers = methodBinding.modifiers; |
2687 |
attributesNumber += generateRuntimeAnnotations(annotations); |
2688 |
if (annotations != null || (modifiers & ExtraCompilerModifiers.AccImplicitlyNonNull) != 0) { |
|
|
2689 |
attributesNumber += generateRuntimeAnnotations(annotations, methodBinding.modifiers); |
2688 |
} |
2690 |
} |
2689 |
if ((methodBinding.tagBits & TagBits.HasParameterAnnotations) != 0) { |
2691 |
if ((methodBinding.tagBits & TagBits.HasParameterAnnotations) != 0) { |
2690 |
Argument[] arguments = methodDeclaration.arguments; |
2692 |
Argument[] arguments = methodDeclaration.arguments; |
Lines 2868-2890
Link Here
|
2868 |
} |
2870 |
} |
2869 |
} |
2871 |
} |
2870 |
|
2872 |
|
|
|
2873 |
private int generateNonNullAttribute() { |
2874 |
TypeBinding nonNullAnnotation; |
2875 |
try { |
2876 |
nonNullAnnotation = this.referenceBinding.fPackage.environment.getNullAnnotationBinding(TagBits.AnnotationNonNull, true); |
2877 |
} catch (NullPointerException npe) { |
2878 |
return 0; // above chain of dereferencing is quite long, difficult to analyse if all are safe |
2879 |
} |
2880 |
int localContentsOffset = this.contentsOffset; |
2881 |
if (localContentsOffset + 6 >= this.contents.length) { |
2882 |
resizeContents(6); |
2883 |
} |
2884 |
int nonNullAttributeNameIndex = this.constantPool.literalIndex(nonNullAnnotation); |
2885 |
this.contents[localContentsOffset++] = (byte) (nonNullAttributeNameIndex >> 8); |
2886 |
this.contents[localContentsOffset++] = (byte) nonNullAttributeNameIndex; |
2887 |
// the length of a nonNull attribute is equals to 0 |
2888 |
this.contents[localContentsOffset++] = 0; |
2889 |
this.contents[localContentsOffset++] = 0; |
2890 |
this.contents[localContentsOffset++] = 0; |
2891 |
this.contents[localContentsOffset++] = 0; |
2892 |
this.contentsOffset = localContentsOffset; |
2893 |
return 1; |
2894 |
} |
2895 |
|
2871 |
/** |
2896 |
/** |
2872 |
* @param annotations |
2897 |
* @param annotations |
|
|
2898 |
* @param modifiers modifiers that could trigger generating an implicit annotation |
2873 |
* @return the number of attributes created while dumping the annotations in the .class file |
2899 |
* @return the number of attributes created while dumping the annotations in the .class file |
2874 |
*/ |
2900 |
*/ |
2875 |
private int generateRuntimeAnnotations(final Annotation[] annotations) { |
2901 |
private int generateRuntimeAnnotations(final Annotation[] annotations, int modifiers) { |
2876 |
int attributesNumber = 0; |
2902 |
int attributesNumber = 0; |
2877 |
final int length = annotations.length; |
|
|
2878 |
int visibleAnnotationsCounter = 0; |
2903 |
int visibleAnnotationsCounter = 0; |
2879 |
int invisibleAnnotationsCounter = 0; |
2904 |
int invisibleAnnotationsCounter = 0; |
2880 |
|
2905 |
|
2881 |
for (int i = 0; i < length; i++) { |
2906 |
if (annotations != null) { |
2882 |
Annotation annotation = annotations[i]; |
2907 |
final int length = annotations.length; |
2883 |
if (annotation.isRuntimeInvisible()) { |
2908 |
for (int i = 0; i < length; i++) { |
2884 |
invisibleAnnotationsCounter++; |
2909 |
Annotation annotation = annotations[i]; |
2885 |
} else if (annotation.isRuntimeVisible()) { |
2910 |
if (annotation.isRuntimeInvisible()) { |
2886 |
visibleAnnotationsCounter++; |
2911 |
invisibleAnnotationsCounter++; |
|
|
2912 |
} else if (annotation.isRuntimeVisible()) { |
2913 |
visibleAnnotationsCounter++; |
2914 |
} |
2887 |
} |
2915 |
} |
|
|
2916 |
} |
2917 |
boolean isImplicitlyNonNull = (modifiers & ExtraCompilerModifiers.AccImplicitlyNonNull) != 0; |
2918 |
if (isImplicitlyNonNull) { |
2919 |
visibleAnnotationsCounter++; |
2888 |
} |
2920 |
} |
2889 |
|
2921 |
|
2890 |
int annotationAttributeOffset = this.contentsOffset; |
2922 |
int annotationAttributeOffset = this.contentsOffset; |
Lines 2905-2919
Link Here
|
2905 |
this.contentsOffset += 2; // leave space for the annotations length |
2937 |
this.contentsOffset += 2; // leave space for the annotations length |
2906 |
|
2938 |
|
2907 |
int counter = 0; |
2939 |
int counter = 0; |
2908 |
loop: for (int i = 0; i < length; i++) { |
2940 |
if (annotations != null) { |
2909 |
if (invisibleAnnotationsCounter == 0) break loop; |
2941 |
final int length = annotations.length; |
2910 |
Annotation annotation = annotations[i]; |
2942 |
loop: for (int i = 0; i < length; i++) { |
2911 |
if (annotation.isRuntimeInvisible()) { |
2943 |
if (invisibleAnnotationsCounter == 0) break loop; |
2912 |
int currentAnnotationOffset = this.contentsOffset; |
2944 |
Annotation annotation = annotations[i]; |
2913 |
generateAnnotation(annotation, currentAnnotationOffset); |
2945 |
if (annotation.isRuntimeInvisible()) { |
2914 |
invisibleAnnotationsCounter--; |
2946 |
int currentAnnotationOffset = this.contentsOffset; |
2915 |
if (this.contentsOffset != currentAnnotationOffset) { |
2947 |
generateAnnotation(annotation, currentAnnotationOffset); |
2916 |
counter++; |
2948 |
invisibleAnnotationsCounter--; |
|
|
2949 |
if (this.contentsOffset != currentAnnotationOffset) { |
2950 |
counter++; |
2951 |
} |
2917 |
} |
2952 |
} |
2918 |
} |
2953 |
} |
2919 |
} |
2954 |
} |
Lines 2952-2966
Link Here
|
2952 |
this.contentsOffset += 2; // leave space for the annotations length |
2987 |
this.contentsOffset += 2; // leave space for the annotations length |
2953 |
|
2988 |
|
2954 |
int counter = 0; |
2989 |
int counter = 0; |
2955 |
loop: for (int i = 0; i < length; i++) { |
2990 |
if (isImplicitlyNonNull) { |
2956 |
if (visibleAnnotationsCounter == 0) break loop; |
2991 |
counter += generateNonNullAttribute(); |
2957 |
Annotation annotation = annotations[i]; |
2992 |
visibleAnnotationsCounter--; |
2958 |
if (annotation.isRuntimeVisible()) { |
2993 |
} |
2959 |
visibleAnnotationsCounter--; |
2994 |
if (annotations != null) { |
2960 |
int currentAnnotationOffset = this.contentsOffset; |
2995 |
final int length = annotations.length; |
2961 |
generateAnnotation(annotation, currentAnnotationOffset); |
2996 |
loop: for (int i = 0; i < length; i++) { |
2962 |
if (this.contentsOffset != currentAnnotationOffset) { |
2997 |
if (visibleAnnotationsCounter == 0) break loop; |
2963 |
counter++; |
2998 |
Annotation annotation = annotations[i]; |
|
|
2999 |
if (annotation.isRuntimeVisible()) { |
3000 |
visibleAnnotationsCounter--; |
3001 |
int currentAnnotationOffset = this.contentsOffset; |
3002 |
generateAnnotation(annotation, currentAnnotationOffset); |
3003 |
if (this.contentsOffset != currentAnnotationOffset) { |
3004 |
counter++; |
3005 |
} |
2964 |
} |
3006 |
} |
2965 |
} |
3007 |
} |
2966 |
} |
3008 |
} |
Lines 3002-3007
Link Here
|
3002 |
visibleParametersAnnotationsCounter++; |
3044 |
visibleParametersAnnotationsCounter++; |
3003 |
} |
3045 |
} |
3004 |
} |
3046 |
} |
|
|
3047 |
} |
3048 |
if ((argument.binding.modifiers & ExtraCompilerModifiers.AccImplicitlyNonNull) != 0) { |
3049 |
visibleParametersAnnotationsCounter++; |
3005 |
} |
3050 |
} |
3006 |
} |
3051 |
} |
3007 |
int attributesNumber = 0; |
3052 |
int attributesNumber = 0; |
Lines 3085-3097
Link Here
|
3085 |
this.contents[this.contentsOffset++] = (byte) 0; |
3130 |
this.contents[this.contentsOffset++] = (byte) 0; |
3086 |
this.contents[this.contentsOffset++] = (byte) 0; |
3131 |
this.contents[this.contentsOffset++] = (byte) 0; |
3087 |
} else { |
3132 |
} else { |
|
|
3133 |
Argument argument = arguments[i]; |
3088 |
final int numberOfVisibleAnnotations = annotationsCounters[i][VISIBLE_INDEX]; |
3134 |
final int numberOfVisibleAnnotations = annotationsCounters[i][VISIBLE_INDEX]; |
3089 |
int visibleAnnotationsOffset = this.contentsOffset; |
3135 |
int visibleAnnotationsOffset = this.contentsOffset; |
3090 |
// leave space for number of annotations |
3136 |
// leave space for number of annotations |
3091 |
this.contentsOffset += 2; |
3137 |
this.contentsOffset += 2; |
3092 |
int counter = 0; |
3138 |
int counter = 0; |
3093 |
if (numberOfVisibleAnnotations != 0) { |
3139 |
if (numberOfVisibleAnnotations != 0) { |
3094 |
Argument argument = arguments[i]; |
|
|
3095 |
Annotation[] annotations = argument.annotations; |
3140 |
Annotation[] annotations = argument.annotations; |
3096 |
for (int j = 0, max = annotations.length; j < max; j++) { |
3141 |
for (int j = 0, max = annotations.length; j < max; j++) { |
3097 |
Annotation annotation = annotations[j]; |
3142 |
Annotation annotation = annotations[j]; |
Lines 3106-3111
Link Here
|
3106 |
} |
3151 |
} |
3107 |
} |
3152 |
} |
3108 |
} |
3153 |
} |
|
|
3154 |
if ((argument.binding.modifiers & ExtraCompilerModifiers.AccImplicitlyNonNull) != 0) { |
3155 |
int generated = generateNonNullAttribute(); |
3156 |
counter+=generated; |
3157 |
globalCounter+=generated; |
3158 |
visibleParametersAnnotationsCounter--; |
3159 |
} |
3109 |
this.contents[visibleAnnotationsOffset++] = (byte) (counter >> 8); |
3160 |
this.contents[visibleAnnotationsOffset++] = (byte) (counter >> 8); |
3110 |
this.contents[visibleAnnotationsOffset] = (byte) counter; |
3161 |
this.contents[visibleAnnotationsOffset] = (byte) counter; |
3111 |
} |
3162 |
} |