Java Code Examples for org.eclipse.jdt.internal.compiler.util.Util#C_RESOLVED
The following examples show how to use
org.eclipse.jdt.internal.compiler.util.Util#C_RESOLVED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BinaryTypeBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private MethodBinding findMethod(char[] methodDescriptor, char[][][] missingTypeNames) { if (!isPrototype()) throw new IllegalStateException(); int index = -1; while (methodDescriptor[++index] != Util.C_PARAM_START) { // empty } char[] selector = new char[index]; System.arraycopy(methodDescriptor, 0, selector, 0, index); TypeBinding[] parameters = Binding.NO_PARAMETERS; int numOfParams = 0; char nextChar; int paramStart = index; while ((nextChar = methodDescriptor[++index]) != Util.C_PARAM_END) { if (nextChar != Util.C_ARRAY) { numOfParams++; if (nextChar == Util.C_RESOLVED) while ((nextChar = methodDescriptor[++index]) != Util.C_NAME_END){/*empty*/} } } if (numOfParams > 0) { parameters = new TypeBinding[numOfParams]; index = paramStart + 1; int end = paramStart; // first character is always '(' so skip it for (int i = 0; i < numOfParams; i++) { while ((nextChar = methodDescriptor[++end]) == Util.C_ARRAY){/*empty*/} if (nextChar == Util.C_RESOLVED) while ((nextChar = methodDescriptor[++end]) != Util.C_NAME_END){/*empty*/} // not interested in type annotations, type will be used for comparison only, and erasure() is used if needed TypeBinding param = this.environment.getTypeFromSignature(methodDescriptor, index, end, false, this, missingTypeNames, TypeAnnotationWalker.EMPTY_ANNOTATION_WALKER); if (param instanceof UnresolvedReferenceBinding) { param = resolveType(param, this.environment, true /* raw conversion */); } parameters[i] = param; index = end + 1; } } int parameterLength = parameters.length; MethodBinding[] methods2 = this.enclosingType.getMethods(selector, parameterLength); // find matching method using parameters loop: for (int i = 0, max = methods2.length; i < max; i++) { MethodBinding currentMethod = methods2[i]; TypeBinding[] parameters2 = currentMethod.parameters; int currentMethodParameterLength = parameters2.length; if (parameterLength == currentMethodParameterLength) { for (int j = 0; j < currentMethodParameterLength; j++) { if (TypeBinding.notEquals(parameters[j], parameters2[j]) && TypeBinding.notEquals(parameters[j].erasure(), parameters2[j].erasure())) { continue loop; } } return currentMethod; } } return null; }
Example 2
Source File: BinaryTypeBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void scanFieldForNullAnnotation(IBinaryField field, FieldBinding fieldBinding, boolean isEnum) { if (!isPrototype()) throw new IllegalStateException(); if (this.environment.globalOptions.sourceLevel >= ClassFileConstants.JDK1_8) { TypeBinding fieldType = fieldBinding.type; if (fieldType != null && !fieldType.isBaseType() && (fieldType.tagBits & TagBits.AnnotationNullMASK) == 0 && hasNonNullDefaultFor(DefaultLocationField, true)) { fieldBinding.type = this.environment.createAnnotatedType(fieldType, new AnnotationBinding[]{this.environment.getNonNullAnnotation()}); } return; // not using fieldBinding.tagBits when we have type annotations. } // global option is checked by caller char[][] nullableAnnotationName = this.environment.getNullableAnnotationName(); char[][] nonNullAnnotationName = this.environment.getNonNullAnnotationName(); if (nullableAnnotationName == null || nonNullAnnotationName == null) return; // not well-configured to use null annotations if (fieldBinding.type == null || fieldBinding.type.isBaseType()) return; // null annotations are only applied to reference types boolean explicitNullness = false; IBinaryAnnotation[] annotations = field.getAnnotations(); if (annotations != null) { for (int i = 0; i < annotations.length; i++) { char[] annotationTypeName = annotations[i].getTypeName(); if (annotationTypeName[0] != Util.C_RESOLVED) continue; char[][] typeName = CharOperation.splitOn('/', annotationTypeName, 1, annotationTypeName.length-1); // cut of leading 'L' and trailing ';' if (CharOperation.equals(typeName, nonNullAnnotationName)) { fieldBinding.tagBits |= TagBits.AnnotationNonNull; explicitNullness = true; break; } if (CharOperation.equals(typeName, nullableAnnotationName)) { fieldBinding.tagBits |= TagBits.AnnotationNullable; explicitNullness = true; break; } } } if (!explicitNullness && (this.tagBits & TagBits.AnnotationNonNullByDefault) != 0) { fieldBinding.tagBits |= TagBits.AnnotationNonNull; } if (isEnum) { if ((field.getModifiers() & ClassFileConstants.AccEnum) != 0) { fieldBinding.tagBits |= TagBits.AnnotationNonNull; } } }
Example 3
Source File: BinaryTypeBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void scanTypeForNullDefaultAnnotation(IBinaryType binaryType, PackageBinding packageBinding, BinaryTypeBinding binaryBinding) { if (!isPrototype()) throw new IllegalStateException(); char[][] nonNullByDefaultAnnotationName = this.environment.getNonNullByDefaultAnnotationName(); if (nonNullByDefaultAnnotationName == null) return; // not well-configured to use null annotations IBinaryAnnotation[] annotations = binaryType.getAnnotations(); boolean isPackageInfo = CharOperation.equals(binaryBinding.sourceName(), TypeConstants.PACKAGE_INFO_NAME); boolean useTypeAnnotations = this.environment.globalOptions.sourceLevel >= ClassFileConstants.JDK1_8; if (annotations != null) { long annotationBit = 0L; int nullness = NO_NULL_DEFAULT; int length = annotations.length; for (int i = 0; i < length; i++) { char[] annotationTypeName = annotations[i].getTypeName(); if (annotationTypeName[0] != Util.C_RESOLVED) continue; char[][] typeName = CharOperation.splitOn('/', annotationTypeName, 1, annotationTypeName.length-1); // cut of leading 'L' and trailing ';' if (CharOperation.equals(typeName, nonNullByDefaultAnnotationName)) { IBinaryElementValuePair[] elementValuePairs = annotations[i].getElementValuePairs(); if (!useTypeAnnotations) { if (elementValuePairs != null && elementValuePairs.length == 1) { Object value = elementValuePairs[0].getValue(); if (value instanceof BooleanConstant && !((BooleanConstant)value).booleanValue()) { // parameter is 'false': this means we cancel defaults from outer scopes: annotationBit = TagBits.AnnotationNullUnspecifiedByDefault; nullness = NULL_UNSPECIFIED_BY_DEFAULT; break; } } } else { // using NonNullByDefault we need to inspect the details of the value() attribute: nullness = getNonNullByDefaultValue(annotations[i]); if (nullness == NULL_UNSPECIFIED_BY_DEFAULT) { annotationBit = TagBits.AnnotationNullUnspecifiedByDefault; } else if (nullness != 0) { annotationBit = TagBits.AnnotationNonNullByDefault; } this.defaultNullness = nullness; break; } annotationBit = TagBits.AnnotationNonNullByDefault; nullness = NONNULL_BY_DEFAULT; break; } } if (annotationBit != 0L) { binaryBinding.tagBits |= annotationBit; if (isPackageInfo) packageBinding.defaultNullness = nullness; return; } } if (isPackageInfo) { // no default annotations found in package-info packageBinding.defaultNullness = Binding.NULL_UNSPECIFIED_BY_DEFAULT; return; } ReferenceBinding enclosingTypeBinding = binaryBinding.enclosingType; if (enclosingTypeBinding != null) { if (useTypeAnnotations) { binaryBinding.defaultNullness = enclosingTypeBinding.getNullDefault(); if (binaryBinding.defaultNullness != 0) { return; } } else { if ((enclosingTypeBinding.tagBits & TagBits.AnnotationNonNullByDefault) != 0) { binaryBinding.tagBits |= TagBits.AnnotationNonNullByDefault; return; } else if ((enclosingTypeBinding.tagBits & TagBits.AnnotationNullUnspecifiedByDefault) != 0) { binaryBinding.tagBits |= TagBits.AnnotationNullUnspecifiedByDefault; return; } } } // no annotation found on the type or its enclosing types // check the package-info for default annotation if not already done before if (packageBinding.defaultNullness == Binding.NO_NULL_DEFAULT && !isPackageInfo) { // this will scan the annotations in package-info ReferenceBinding packageInfo = packageBinding.getType(TypeConstants.PACKAGE_INFO_NAME); if (packageInfo == null) { packageBinding.defaultNullness = Binding.NULL_UNSPECIFIED_BY_DEFAULT; } } // no @NonNullByDefault at type level, check containing package: if (useTypeAnnotations) { binaryBinding.defaultNullness = packageBinding.defaultNullness; } else { switch (packageBinding.defaultNullness) { case Binding.NONNULL_BY_DEFAULT : binaryBinding.tagBits |= TagBits.AnnotationNonNullByDefault; break; case Binding.NULL_UNSPECIFIED_BY_DEFAULT : binaryBinding.tagBits |= TagBits.AnnotationNullUnspecifiedByDefault; break; } } }