char[] variableName = CharOperation.subarray(typeSignature, i, colon); TypeVariableBinding typeVariable = new TypeVariableBinding(variableName, this, rank, this.environment); AnnotationBinding [] annotations = BinaryTypeBinding.createAnnotations(walker.toTypeParameter(isClassTypeParameter, rank++).getAnnotationsAtCursor(0), this.environment, missingTypeNames); if (annotations != null && annotations != Binding.NO_ANNOTATIONS) this.typeVariables = result; for (int i = 0; i < rank; i++) { initializeTypeVariable(result[i], result, wrapper, missingTypeNames, walker.toTypeParameterBounds(isClassTypeParameter, i)); if (this.externalAnnotationStatus.isPotentiallyUnannotatedLib() && result[i].hasNullTypeAnnotations()) this.externalAnnotationStatus = ExternalAnnotationStatus.TYPE_IS_ANNOTATED;
@Override public boolean visit(ArrayBinding arrayBinding) { ExternalAnnotationSuperimposer memento = snapshot(); try { int dims = arrayBinding.dimensions; AnnotationBinding[][] annotsOnDims = new AnnotationBinding[dims][]; ITypeAnnotationWalker walker = this.currentWalker; for (int i = 0; i < dims; i++) { IBinaryAnnotation[] binaryAnnotations = walker.getAnnotationsAtCursor(arrayBinding.id); if (binaryAnnotations != ITypeAnnotationWalker.NO_ANNOTATIONS) { annotsOnDims[i] = BinaryTypeBinding.createAnnotations(binaryAnnotations, this.environment, null); this.isReplacing = true; } else { annotsOnDims[i] = Binding.NO_ANNOTATIONS; } walker = walker.toNextArrayDimension(); } TypeBinding leafComponentType = goAndSuperimpose(walker, arrayBinding.leafComponentType()); if (this.isReplacing) { this.typeReplacement = this.environment.createArrayType(leafComponentType, dims, AnnotatableTypeSystem.flattenedAnnotations(annotsOnDims)); } } finally { restore(memento); } return false; } @Override
private TypeBinding annotateType(TypeBinding binding, ITypeAnnotationWalker walker, char[][][] missingTypeNames) { int depth = binding.depth() + 1; if (depth > 1) { // need to count non-static nesting levels, resolved binding required for precision if (binding.isUnresolvedType()) binding = ((UnresolvedReferenceBinding) binding).resolve(this, true); depth = countNonStaticNestingLevels(binding) + 1; } AnnotationBinding [][] annotations = null; for (int i = 0; i < depth; i++) { AnnotationBinding[] annots = BinaryTypeBinding.createAnnotations(walker.getAnnotationsAtCursor(binding.id, i == depth - 1), this, missingTypeNames); if (annots != null && annots.length > 0) { if (annotations == null) annotations = new AnnotationBinding[depth][]; annotations[i] = annots; } walker = walker.toNextNestedType(); } if (annotations != null) binding = createAnnotatedType(binding, annotations); return binding; }
TypeBinding bound = getTypeFromTypeSignature(wrapper, staticVariables, enclosingType, missingTypeNames, walker.toWildcardBound()); AnnotationBinding [] annotations = BinaryTypeBinding.createAnnotations(walker.getAnnotationsAtCursor(-1), this, missingTypeNames); return this.typeSystem.getWildcard(genericType, rank, bound, null /*no extra bound*/, Wildcard.SUPER, annotations); case '+' : bound = getTypeFromTypeSignature(wrapper, staticVariables, enclosingType, missingTypeNames, walker.toWildcardBound()); annotations = BinaryTypeBinding.createAnnotations(walker.getAnnotationsAtCursor(-1), this, missingTypeNames); return this.typeSystem.getWildcard(genericType, rank, bound, null /*no extra bound*/, Wildcard.EXTENDS, annotations); case '*' : annotations = BinaryTypeBinding.createAnnotations(walker.getAnnotationsAtCursor(-1), this, missingTypeNames); return this.typeSystem.getWildcard(genericType, rank, null, null /*no extra bound*/, Wildcard.UNBOUND, annotations); default :
parameters[i - startIndex] = this.environment.getTypeFromSignature(methodDescriptor, index, end, false, this, missingTypeNames, walker.toMethodParameter(visibleIdx++)); exceptions = new ReferenceBinding[size]; for (int i = 0; i < size; i++) exceptions[i] = this.environment.getTypeFromConstantPoolName(exceptionTypes[i], 0, -1, false, missingTypeNames, walker.toThrows(i)); returnType = this.environment.getTypeFromSignature(methodDescriptor, index + 1, -1, false, this, missingTypeNames, walker.toMethodReturn()); // index is currently pointing at the ')' short rank = 0; while (wrapper.signature[wrapper.start] != Util.C_PARAM_END) types.add(this.environment.getTypeFromTypeSignature(wrapper, typeVars, this, missingTypeNames, walker.toMethodParameter(rank++))); returnType = this.environment.getTypeFromTypeSignature(wrapper, typeVars, this, missingTypeNames, walker.toMethodReturn()); walker.toThrows(excRank++))); } while (!wrapper.atEnd() && wrapper.signature[wrapper.start] == Util.C_EXCEPTION_START); exceptions = new ReferenceBinding[types.size()]; exceptions = new ReferenceBinding[size]; for (int i = 0; i < size; i++) exceptions[i] = this.environment.getTypeFromConstantPoolName(exceptionTypes[i], 0, -1, false, missingTypeNames, walker.toThrows(i)); IBinaryAnnotation[] receiverAnnotations = walker.toReceiver().getAnnotationsAtCursor(this.id); if (receiverAnnotations != null && receiverAnnotations.length > 0) { result.receiver = this.environment.createAnnotatedType(this, createAnnotations(receiverAnnotations, this.environment, missingTypeNames)); if (annotations == null || annotations.length == 0) if (method.isConstructor()) annotations = walker.toMethodReturn().getAnnotationsAtCursor(this.id); // FIXME: When both exist, order could become an issue.
public static void annotateMethodBinding(MethodBinding method, ExternalAnnotationProvider provider, LookupEnvironment environment) { char[] methodSignature = method.genericSignature(); if (methodSignature == null) methodSignature = method.signature(); ITypeAnnotationWalker walker = provider.forMethod(method.selector, methodSignature, environment); if (walker != null && walker != ITypeAnnotationWalker.EMPTY_ANNOTATION_WALKER) { ExternalAnnotationSuperimposer visitor = new ExternalAnnotationSuperimposer(environment); TypeVariableBinding[] typeParams = method.typeVariables; for (short i = 0; i < typeParams.length; i++) { if (visitor.go(walker.toTypeParameter(false, i))) typeParams[i] = visitor.superimpose(typeParams[i], TypeVariableBinding.class); } if (!method.isConstructor()) { if (visitor.go(walker.toMethodReturn())) method.returnType = visitor.superimpose(method.returnType, TypeBinding.class); } TypeBinding[] parameters = method.parameters; for (short i = 0; i < parameters.length; i++) { if (visitor.go(walker.toMethodParameter(i))) parameters[i] = visitor.superimpose(parameters[i], TypeBinding.class); } } }
if (dimension > 0 && walker != ITypeAnnotationWalker.EMPTY_ANNOTATION_WALKER) { for (int i = 0; i < dimension; i++) { AnnotationBinding [] annotations = BinaryTypeBinding.createAnnotations(walker.getAnnotationsAtCursor(0), this, missingTypeNames); if (annotations != Binding.NO_ANNOTATIONS) { if (annotationsOnDimensions == null) annotationsOnDimensions[i] = annotations; walker = walker.toNextArrayDimension(); actualEnclosing = (ReferenceBinding) convertToRawType(actualEnclosing, false /*do not force conversion of enclosing types*/); AnnotationBinding [] annotations = BinaryTypeBinding.createAnnotations(walker.getAnnotationsAtCursor(actualType.id), this, missingTypeNames); TypeBinding[] typeArguments = getTypeArgumentsFromSignature(wrapper, staticVariables, enclosingType, actualType, missingTypeNames, walker); ParameterizedTypeBinding parameterizedType = createParameterizedType(actualType, typeArguments, actualEnclosing, annotations); walker = walker.toNextNestedType(); annotations = BinaryTypeBinding.createAnnotations(walker.getAnnotationsAtCursor(memberType.id), this, missingTypeNames); if (wrapper.signature[wrapper.start] == '<') {
ITypeAnnotationWalker returnWalker = externalAnnotationWalker.toMethodReturn(); IBinaryAnnotation[] annotations = returnWalker != ITypeAnnotationWalker.EMPTY_ANNOTATION_WALKER ? returnWalker.getAnnotationsAtCursor(methodBinding.returnType.id) : method.getAnnotations(); if (annotations != null) { if (numParamAnnotations > 0) { int startIndex = numParamAnnotations - numVisibleParams; ITypeAnnotationWalker parameterWalker = externalAnnotationWalker.toMethodParameter((short) (j+startIndex)); IBinaryAnnotation[] paramAnnotations = parameterWalker != ITypeAnnotationWalker.EMPTY_ANNOTATION_WALKER ? parameterWalker.getAnnotationsAtCursor(parameters[j].id) : method.getParameterAnnotations(j+startIndex, this.fileName); if (paramAnnotations != null) {
@Override public boolean visit(ParameterizedTypeBinding parameterizedTypeBinding) { ExternalAnnotationSuperimposer memento = snapshot(); try { IBinaryAnnotation[] binaryAnnotations = this.currentWalker.getAnnotationsAtCursor(parameterizedTypeBinding.id); AnnotationBinding[] annotations = Binding.NO_ANNOTATIONS; if (binaryAnnotations != ITypeAnnotationWalker.NO_ANNOTATIONS) { annotations = BinaryTypeBinding.createAnnotations(binaryAnnotations, this.environment, null); this.isReplacing = true; } TypeBinding[] typeArguments = parameterizedTypeBinding.typeArguments(); TypeBinding[] newArguments = new TypeBinding[typeArguments.length]; for (int i = 0; i < typeArguments.length; i++) { newArguments[i] = goAndSuperimpose(memento.currentWalker.toTypeArgument(i), typeArguments[i]); } if (this.isReplacing) this.typeReplacement = this.environment.createParameterizedType(parameterizedTypeBinding.genericType(), newArguments, parameterizedTypeBinding.enclosingType(), annotations); return false; } finally { restore(memento); } } @Override
@Override public boolean visit(ReferenceBinding referenceBinding) { IBinaryAnnotation[] binaryAnnotations = this.currentWalker.getAnnotationsAtCursor(referenceBinding.id); if (binaryAnnotations != ITypeAnnotationWalker.NO_ANNOTATIONS) this.typeReplacement = this.environment.createAnnotatedType(referenceBinding, BinaryTypeBinding.createAnnotations(binaryAnnotations, this.environment, null)); return false; } @Override
private TypeBinding[] getTypeArgumentsFromSignature(SignatureWrapper wrapper, TypeVariableBinding[] staticVariables, ReferenceBinding enclosingType, ReferenceBinding genericType, char[][][] missingTypeNames, ITypeAnnotationWalker walker) { java.util.ArrayList args = new java.util.ArrayList(2); int rank = 0; do { args.add(getTypeFromVariantTypeSignature(wrapper, staticVariables, enclosingType, genericType, rank, missingTypeNames, walker.toTypeArgument(rank++))); } while (wrapper.signature[wrapper.start] != '>'); wrapper.start++; // skip '>' TypeBinding[] typeArguments = new TypeBinding[args.size()]; args.toArray(typeArguments); return typeArguments; }
walker = binaryType.enrichWithExternalAnnotationsFor(walker, iFields[i], this.environment); walker = walker.toField(); TypeBinding type = fieldSignature == null ? this.environment.getTypeFromSignature(binaryField.getTypeName(), 0, -1, false, this, missingTypeNames, walker)
if (superclassName != null) { this.superclass = this.environment.getTypeFromConstantPoolName(superclassName, 0, -1, false, missingTypeNames, toplevelWalker.toSupertype((short) -1, superclassName)); this.tagBits |= TagBits.HasUnresolvedSuperclass; for (short i = 0; i < size; i++) this.superInterfaces[i] = this.environment.getTypeFromConstantPoolName(interfaceNames[i], 0, -1, false, missingTypeNames, toplevelWalker.toSupertype(i, superclassName)); this.tagBits |= TagBits.HasUnresolvedSuperinterfaces; toplevelWalker.toSupertype((short) -1, wrapper.peekFullType())); this.tagBits |= TagBits.HasUnresolvedSuperclass; short rank = 0; do { types.add(this.environment.getTypeFromTypeSignature(wrapper, typeVars, this, missingTypeNames, toplevelWalker.toSupertype(rank++, wrapper.peekFullType()))); } while (!wrapper.atEnd()); this.superInterfaces = new ReferenceBinding[types.size()];
parameters[i - startIndex] = this.environment.getTypeFromSignature(methodDescriptor, index, end, false, this, missingTypeNames, walker.toMethodParameter(visibleIdx++)); exceptions = new ReferenceBinding[size]; for (int i = 0; i < size; i++) exceptions[i] = this.environment.getTypeFromConstantPoolName(exceptionTypes[i], 0, -1, false, missingTypeNames, walker.toThrows(i)); returnType = this.environment.getTypeFromSignature(methodDescriptor, index + 1, -1, false, this, missingTypeNames, walker.toMethodReturn()); // index is currently pointing at the ')' short rank = 0; while (wrapper.signature[wrapper.start] != Util.C_PARAM_END) types.add(this.environment.getTypeFromTypeSignature(wrapper, typeVars, this, missingTypeNames, walker.toMethodParameter(rank++))); returnType = this.environment.getTypeFromTypeSignature(wrapper, typeVars, this, missingTypeNames, walker.toMethodReturn()); walker.toThrows(excRank++))); } while (!wrapper.atEnd() && wrapper.signature[wrapper.start] == Util.C_EXCEPTION_START); exceptions = new ReferenceBinding[types.size()]; exceptions = new ReferenceBinding[size]; for (int i = 0; i < size; i++) exceptions[i] = this.environment.getTypeFromConstantPoolName(exceptionTypes[i], 0, -1, false, missingTypeNames, walker.toThrows(i)); IBinaryAnnotation[] receiverAnnotations = walker.toReceiver().getAnnotationsAtCursor(this.id); if (receiverAnnotations != null && receiverAnnotations.length > 0) { result.receiver = this.environment.createAnnotatedType(this, createAnnotations(receiverAnnotations, this.environment, missingTypeNames)); if (annotations == null || annotations.length == 0) if (method.isConstructor()) annotations = walker.toMethodReturn().getAnnotationsAtCursor(this.id); // FIXME: When both exist, order could become an issue.
public static void annotateMethodBinding(MethodBinding method, ExternalAnnotationProvider provider, LookupEnvironment environment) { char[] methodSignature = method.genericSignature(); if (methodSignature == null) methodSignature = method.signature(); ITypeAnnotationWalker walker = provider.forMethod(method.selector, methodSignature, environment); if (walker != null && walker != ITypeAnnotationWalker.EMPTY_ANNOTATION_WALKER) { ExternalAnnotationSuperimposer visitor = new ExternalAnnotationSuperimposer(environment); TypeVariableBinding[] typeParams = method.typeVariables; for (short i = 0; i < typeParams.length; i++) { if (visitor.go(walker.toTypeParameter(false, i))) typeParams[i] = visitor.superimpose(typeParams[i], TypeVariableBinding.class); } if (!method.isConstructor()) { if (visitor.go(walker.toMethodReturn())) method.returnType = visitor.superimpose(method.returnType, TypeBinding.class); } TypeBinding[] parameters = method.parameters; for (short i = 0; i < parameters.length; i++) { if (visitor.go(walker.toMethodParameter(i))) parameters[i] = visitor.superimpose(parameters[i], TypeBinding.class); } } }
if (dimension > 0 && walker != ITypeAnnotationWalker.EMPTY_ANNOTATION_WALKER) { for (int i = 0; i < dimension; i++) { AnnotationBinding [] annotations = BinaryTypeBinding.createAnnotations(walker.getAnnotationsAtCursor(0), this, missingTypeNames); if (annotations != Binding.NO_ANNOTATIONS) { if (annotationsOnDimensions == null) annotationsOnDimensions[i] = annotations; walker = walker.toNextArrayDimension(); actualEnclosing = (ReferenceBinding) convertToRawType(actualEnclosing, false /*do not force conversion of enclosing types*/); AnnotationBinding [] annotations = BinaryTypeBinding.createAnnotations(walker.getAnnotationsAtCursor(actualType.id), this, missingTypeNames); TypeBinding[] typeArguments = getTypeArgumentsFromSignature(wrapper, staticVariables, enclosingType, actualType, missingTypeNames, walker); ParameterizedTypeBinding parameterizedType = createParameterizedType(actualType, typeArguments, actualEnclosing, annotations); walker = walker.toNextNestedType(); annotations = BinaryTypeBinding.createAnnotations(walker.getAnnotationsAtCursor(memberType.id), this, missingTypeNames); if (wrapper.signature[wrapper.start] == '<') {
ITypeAnnotationWalker returnWalker = externalAnnotationWalker.toMethodReturn(); IBinaryAnnotation[] annotations = returnWalker != ITypeAnnotationWalker.EMPTY_ANNOTATION_WALKER ? returnWalker.getAnnotationsAtCursor(methodBinding.returnType.id) : method.getAnnotations(); if (annotations != null) { if (numParamAnnotations > 0) { int startIndex = numParamAnnotations - numVisibleParams; ITypeAnnotationWalker parameterWalker = externalAnnotationWalker.toMethodParameter((short) (j+startIndex)); IBinaryAnnotation[] paramAnnotations = parameterWalker != ITypeAnnotationWalker.EMPTY_ANNOTATION_WALKER ? parameterWalker.getAnnotationsAtCursor(parameters[j].id) : method.getParameterAnnotations(j+startIndex, this.fileName); if (paramAnnotations != null) {
TypeBinding bound = getTypeFromTypeSignature(wrapper, staticVariables, enclosingType, missingTypeNames, walker.toWildcardBound()); AnnotationBinding [] annotations = BinaryTypeBinding.createAnnotations(walker.getAnnotationsAtCursor(-1, false), this, missingTypeNames); return this.typeSystem.getWildcard(genericType, rank, bound, null /*no extra bound*/, Wildcard.SUPER, annotations); case '+' : bound = getTypeFromTypeSignature(wrapper, staticVariables, enclosingType, missingTypeNames, walker.toWildcardBound()); annotations = BinaryTypeBinding.createAnnotations(walker.getAnnotationsAtCursor(-1, false), this, missingTypeNames); return this.typeSystem.getWildcard(genericType, rank, bound, null /*no extra bound*/, Wildcard.EXTENDS, annotations); case '*' : annotations = BinaryTypeBinding.createAnnotations(walker.getAnnotationsAtCursor(-1, false), this, missingTypeNames); return this.typeSystem.getWildcard(genericType, rank, null, null /*no extra bound*/, Wildcard.UNBOUND, annotations); default :
@Override public boolean visit(ParameterizedTypeBinding parameterizedTypeBinding) { ExternalAnnotationSuperimposer memento = snapshot(); try { IBinaryAnnotation[] binaryAnnotations = this.currentWalker.getAnnotationsAtCursor(parameterizedTypeBinding.id, false); AnnotationBinding[] annotations = Binding.NO_ANNOTATIONS; if (binaryAnnotations != ITypeAnnotationWalker.NO_ANNOTATIONS) { annotations = BinaryTypeBinding.createAnnotations(binaryAnnotations, this.environment, null); this.isReplacing = true; } TypeBinding[] typeArguments = parameterizedTypeBinding.typeArguments(); TypeBinding[] newArguments = new TypeBinding[typeArguments.length]; for (int i = 0; i < typeArguments.length; i++) { newArguments[i] = goAndSuperimpose(memento.currentWalker.toTypeArgument(i), typeArguments[i]); } if (this.isReplacing) this.typeReplacement = this.environment.createParameterizedType(parameterizedTypeBinding.genericType(), newArguments, parameterizedTypeBinding.enclosingType(), annotations); return false; } finally { restore(memento); } } @Override
@Override public boolean visit(ReferenceBinding referenceBinding) { IBinaryAnnotation[] binaryAnnotations = this.currentWalker.getAnnotationsAtCursor(referenceBinding.id, false); if (binaryAnnotations != ITypeAnnotationWalker.NO_ANNOTATIONS) this.typeReplacement = this.environment.createAnnotatedType(referenceBinding, BinaryTypeBinding.createAnnotations(binaryAnnotations, this.environment, null)); return false; } @Override