Java Code Examples for org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants#JDK1_8
The following examples show how to use
org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants#JDK1_8 .
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: LookupEnvironment.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public LookupEnvironment(ITypeRequestor typeRequestor, CompilerOptions globalOptions, ProblemReporter problemReporter, INameEnvironment nameEnvironment) { this.typeRequestor = typeRequestor; this.globalOptions = globalOptions; this.problemReporter = problemReporter; this.defaultPackage = new PackageBinding(this); // assume the default package always exists this.defaultImports = null; this.nameEnvironment = nameEnvironment; this.knownPackages = new HashtableOfPackage(); this.uniqueParameterizedGenericMethodBindings = new SimpleLookupTable(3); this.uniquePolymorphicMethodBindings = new SimpleLookupTable(3); this.missingTypes = null; this.accessRestrictions = new HashMap(3); this.classFilePool = ClassFilePool.newInstance(); this.typesBeingConnected = new HashSet(); this.typeSystem = this.globalOptions.sourceLevel >= ClassFileConstants.JDK1_8 && this.globalOptions.storeAnnotations ? new AnnotatableTypeSystem(this) : new TypeSystem(this); }
Example 2
Source File: MethodBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Compute the tagbits for standard annotations. For source types, these could require * lazily resolving corresponding annotation nodes, in case of forward references. * @see org.eclipse.jdt.internal.compiler.lookup.Binding#getAnnotationTagBits() */ public long getAnnotationTagBits() { MethodBinding originalMethod = original(); if ((originalMethod.tagBits & TagBits.AnnotationResolved) == 0 && originalMethod.declaringClass instanceof SourceTypeBinding) { ClassScope scope = ((SourceTypeBinding) originalMethod.declaringClass).scope; if (scope != null) { TypeDeclaration typeDecl = scope.referenceContext; AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(originalMethod); if (methodDecl != null) ASTNode.resolveAnnotations(methodDecl.scope, methodDecl.annotations, originalMethod); CompilerOptions options = scope.compilerOptions(); if (options.isAnnotationBasedNullAnalysisEnabled) { boolean isJdk18 = options.sourceLevel >= ClassFileConstants.JDK1_8; long nullDefaultBits = isJdk18 ? this.defaultNullness : this.tagBits & (TagBits.AnnotationNonNullByDefault|TagBits.AnnotationNullUnspecifiedByDefault); if (nullDefaultBits != 0 && this.declaringClass instanceof SourceTypeBinding) { SourceTypeBinding declaringSourceType = (SourceTypeBinding) this.declaringClass; if (declaringSourceType.checkRedundantNullnessDefaultOne(methodDecl, methodDecl.annotations, nullDefaultBits, isJdk18)) { declaringSourceType.checkRedundantNullnessDefaultRecurse(methodDecl, methodDecl.annotations, nullDefaultBits, isJdk18); } } } } } return originalMethod.tagBits; }
Example 3
Source File: ReturnStatement.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
void checkAgainstNullAnnotation(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo) { int nullStatus = this.expression.nullStatus(flowInfo, flowContext); long tagBits; MethodBinding methodBinding = null; boolean useTypeAnnotations = scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8; try { methodBinding = scope.methodScope().referenceMethodBinding(); tagBits = (useTypeAnnotations) ? methodBinding.returnType.tagBits : methodBinding.tagBits; } catch (NullPointerException npe) { // chain of references in try-block has several potential nulls; // any null means we cannot perform the following check return; } if (useTypeAnnotations) { checkAgainstNullTypeAnnotation(scope, methodBinding.returnType, this.expression, flowContext, flowInfo); } else if (nullStatus != FlowInfo.NON_NULL) { // if we can't prove non-null check against declared null-ness of the enclosing method: if ((tagBits & TagBits.AnnotationNonNull) != 0) { flowContext.recordNullityMismatch(scope, this.expression, this.expression.resolvedType, methodBinding.returnType, nullStatus); } } }
Example 4
Source File: MethodVerifier15.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
void checkAgainstInheritedMethods(MethodBinding currentMethod, MethodBinding[] methods, int length, MethodBinding[] allInheritedMethods) { super.checkAgainstInheritedMethods(currentMethod, methods, length, allInheritedMethods); CompilerOptions options = this.environment.globalOptions; if (options.isAnnotationBasedNullAnalysisEnabled && (currentMethod.tagBits & TagBits.IsNullnessKnown) == 0) { // if annotations are inherited these have been checked during STB.resolveTypesFor() (for methods explicit in this.type) AbstractMethodDeclaration srcMethod = null; if (this.type.equals(currentMethod.declaringClass)) // is currentMethod from the current type? srcMethod = currentMethod.sourceMethod(); boolean useTypeAnnotations = options.sourceLevel >= ClassFileConstants.JDK1_8; boolean hasNonNullDefault = currentMethod.hasNonNullDefaultFor(Binding.DefaultLocationParameter|Binding.DefaultLocationReturnType, useTypeAnnotations); for (int i = length; --i >= 0;) if (!currentMethod.isStatic() && !methods[i].isStatic()) checkNullSpecInheritance(currentMethod, srcMethod, hasNonNullDefault, true, methods[i], this.type.scope, null); } }
Example 5
Source File: Argument.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public TypeBinding createBinding(MethodScope scope, TypeBinding typeBinding) { if (this.binding == null) { // for default constructors and fake implementation of abstract methods this.binding = new LocalVariableBinding(this, typeBinding, this.modifiers, scope); } else if (!this.binding.type.isValidBinding()) { AbstractMethodDeclaration methodDecl = scope.referenceMethod(); if (methodDecl != null) { MethodBinding methodBinding = methodDecl.binding; if (methodBinding != null) { methodBinding.tagBits |= TagBits.HasUnresolvedArguments; } } } if ((this.binding.tagBits & TagBits.AnnotationResolved) == 0) { resolveAnnotations(scope, this.annotations, this.binding, true); if (scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8) { Annotation.isTypeUseCompatible(this.type, scope, this.annotations); scope.validateNullAnnotation(this.binding.tagBits, this.type, this.annotations); } } this.binding.declaration = this; return this.binding.type; // might have been updated during resolveAnnotations (for typeAnnotations) }
Example 6
Source File: AbstractMethodDeclaration.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
static void createArgumentBindings(Argument[] arguments, MethodBinding binding, MethodScope scope) { boolean useTypeAnnotations = scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8; if (arguments != null && binding != null) { for (int i = 0, length = arguments.length; i < length; i++) { Argument argument = arguments[i]; binding.parameters[i] = argument.createBinding(scope, binding.parameters[i]); if (useTypeAnnotations) continue; // no business with SE7 null annotations in the 1.8 case. // createBinding() has resolved annotations, now transfer nullness info from the argument to the method: long argTypeTagBits = (argument.binding.tagBits & TagBits.AnnotationNullMASK); if (argTypeTagBits != 0) { if (binding.parameterNonNullness == null) { binding.parameterNonNullness = new Boolean[arguments.length]; binding.tagBits |= TagBits.IsNullnessKnown; } binding.parameterNonNullness[i] = Boolean.valueOf(argTypeTagBits == TagBits.AnnotationNonNull); } } } }
Example 7
Source File: FieldBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void fillInDefaultNonNullness(FieldDeclaration sourceField, Scope scope) { LookupEnvironment environment = scope.environment(); if ( this.type != null && !this.type.isBaseType() && (this.tagBits & TagBits.AnnotationNullMASK) == 0) { if (environment.globalOptions.sourceLevel < ClassFileConstants.JDK1_8) this.tagBits |= TagBits.AnnotationNonNull; else this.type = environment.createAnnotatedType(this.type, new AnnotationBinding[]{environment.getNonNullAnnotation()}); } else if ((this.tagBits & TagBits.AnnotationNonNull) != 0) { scope.problemReporter().nullAnnotationIsRedundant(sourceField); } }
Example 8
Source File: ImplicitNullAnnotationVerifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
void applyReturnNullBits(MethodBinding method, long nullnessBits) { if (this.environment.globalOptions.sourceLevel < ClassFileConstants.JDK1_8) { method.tagBits |= nullnessBits; } else { if (!method.returnType.isBaseType()) { method.returnType = this.environment.createAnnotatedType(method.returnType, this.environment.nullAnnotationsFromTagBits(nullnessBits)); } } }
Example 9
Source File: ParameterizedTypeBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * @see org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#methods() */ public MethodBinding[] methods() { if ((this.tagBits & TagBits.AreMethodsComplete) != 0) return this.methods; try { MethodBinding[] originalMethods = this.type.methods(); int length = originalMethods.length; MethodBinding[] parameterizedMethods = new MethodBinding[length]; CompilerOptions options = this.environment.globalOptions; boolean useNullTypeAnnotations = options.isAnnotationBasedNullAnalysisEnabled && options.sourceLevel >= ClassFileConstants.JDK1_8; for (int i = 0; i < length; i++) { // substitute all methods, so as to get updated declaring class at least parameterizedMethods[i] = createParameterizedMethod(originalMethods[i]); if (useNullTypeAnnotations) parameterizedMethods[i] = NullAnnotationMatching.checkForContraditions(parameterizedMethods[i], null, null); } this.methods = parameterizedMethods; } finally { // if the original methods cannot be retrieved (ex. AbortCompilation), then assume we do not have any methods if (this.methods == null) this.methods = Binding.NO_METHODS; this.tagBits |= TagBits.AreMethodsComplete; } return this.methods; }
Example 10
Source File: FieldDeclaration.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public FlowInfo analyseCode(MethodScope initializationScope, FlowContext flowContext, FlowInfo flowInfo) { if (this.binding != null && !this.binding.isUsed() && this.binding.isOrEnclosedByPrivateType()) { if (!initializationScope.referenceCompilationUnit().compilationResult.hasSyntaxError) { initializationScope.problemReporter().unusedPrivateField(this); } } // cannot define static non-constant field inside nested class if (this.binding != null && this.binding.isValidBinding() && this.binding.isStatic() && this.binding.constant() == Constant.NotAConstant && this.binding.declaringClass.isNestedType() && !this.binding.declaringClass.isStatic()) { initializationScope.problemReporter().unexpectedStaticModifierForField( (SourceTypeBinding) this.binding.declaringClass, this); } if (this.initialization != null) { flowInfo = this.initialization .analyseCode(initializationScope, flowContext, flowInfo) .unconditionalInits(); flowInfo.markAsDefinitelyAssigned(this.binding); } if (this.initialization != null && this.binding != null) { CompilerOptions options = initializationScope.compilerOptions(); if (options.isAnnotationBasedNullAnalysisEnabled) { if (this.binding.isNonNull() || options.sourceLevel >= ClassFileConstants.JDK1_8) { int nullStatus = this.initialization.nullStatus(flowInfo, flowContext); NullAnnotationMatching.checkAssignment(initializationScope, flowContext, this.binding, nullStatus, this.initialization, this.initialization.resolvedType); } } this.initialization.checkNPEbyUnboxing(initializationScope, flowContext, flowInfo); } return flowInfo; }
Example 11
Source File: Annotation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void isTypeUseCompatible(TypeReference reference, Scope scope, Annotation[] annotations) { if (annotations == null || reference == null || reference.getAnnotatableLevels() == 1) return; if (scope.environment().globalOptions.sourceLevel < ClassFileConstants.JDK1_8) return; TypeBinding resolvedType = reference.resolvedType == null ? null : reference.resolvedType.leafComponentType(); if (resolvedType == null || !resolvedType.isNestedType()) return; nextAnnotation: for (int i = 0, annotationsLength = annotations.length; i < annotationsLength; i++) { Annotation annotation = annotations[i]; long metaTagBits = annotation.resolvedType.getAnnotationTagBits(); if ((metaTagBits & TagBits.AnnotationForTypeUse) != 0 && (metaTagBits & TagBits.SE7AnnotationTargetMASK) == 0) { ReferenceBinding currentType = (ReferenceBinding) resolvedType; while (currentType.isNestedType()) { if (currentType.isStatic()) { QualifiedTypeReference.rejectAnnotationsOnStaticMemberQualififer(scope, currentType, new Annotation [] { annotation }); continue nextAnnotation; } else { int id = annotation.resolvedType.id; if (id == TypeIds.T_ConfiguredAnnotationNonNull || id == TypeIds.T_ConfiguredAnnotationNullable) { scope.problemReporter().nullAnnotationUnsupportedLocation(annotation); continue nextAnnotation; } } currentType = currentType.enclosingType(); } } } }
Example 12
Source File: CompilerOptions.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static long versionToJdkLevel(Object versionID) { if (versionID instanceof String) { String version = (String) versionID; // verification is optimized for all versions with same length and same "1." prefix if (version.length() == 3 && version.charAt(0) == '1' && version.charAt(1) == '.') { switch (version.charAt(2)) { case '1': return ClassFileConstants.JDK1_1; case '2': return ClassFileConstants.JDK1_2; case '3': return ClassFileConstants.JDK1_3; case '4': return ClassFileConstants.JDK1_4; case '5': return ClassFileConstants.JDK1_5; case '6': return ClassFileConstants.JDK1_6; case '7': return ClassFileConstants.JDK1_7; case '8': return ClassFileConstants.JDK1_8; default: return 0; // unknown } } if (VERSION_JSR14.equals(versionID)) { return ClassFileConstants.JDK1_4; } if (VERSION_CLDC1_1.equals(versionID)) { return ClassFileConstants.CLDC_1_1; } } return 0; // unknown }
Example 13
Source File: NullAnnotationMatching.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** Check null-ness of 'var' against a possible null annotation */ public static int checkAssignment(BlockScope currentScope, FlowContext flowContext, VariableBinding var, int nullStatus, Expression expression, TypeBinding providedType) { long lhsTagBits = 0L; boolean hasReported = false; if (currentScope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_8) { lhsTagBits = var.tagBits & TagBits.AnnotationNullMASK; } else { if (expression instanceof ConditionalExpression && expression.isPolyExpression()) { // drill into both branches: ConditionalExpression ce = ((ConditionalExpression) expression); int status1 = NullAnnotationMatching.checkAssignment(currentScope, flowContext, var, ce.ifTrueNullStatus, ce.valueIfTrue, ce.valueIfTrue.resolvedType); int status2 = NullAnnotationMatching.checkAssignment(currentScope, flowContext, var, ce.ifFalseNullStatus, ce.valueIfFalse, ce.valueIfFalse.resolvedType); if (status1 == status2) return status1; return nullStatus; // if both branches disagree use the precomputed & merged nullStatus } lhsTagBits = var.type.tagBits & TagBits.AnnotationNullMASK; NullAnnotationMatching annotationStatus = analyse(var.type, providedType, nullStatus); if (annotationStatus.isDefiniteMismatch()) { currentScope.problemReporter().nullityMismatchingTypeAnnotation(expression, providedType, var.type, annotationStatus); hasReported = true; } else if (annotationStatus.isUnchecked()) { flowContext.recordNullityMismatch(currentScope, expression, providedType, var.type, nullStatus); hasReported = true; } else if (annotationStatus.nullStatus != FlowInfo.UNKNOWN) { return annotationStatus.nullStatus; } } if (lhsTagBits == TagBits.AnnotationNonNull && nullStatus != FlowInfo.NON_NULL) { if (!hasReported) flowContext.recordNullityMismatch(currentScope, expression, providedType, var.type, nullStatus); return FlowInfo.NON_NULL; } else if (lhsTagBits == TagBits.AnnotationNullable && nullStatus == FlowInfo.UNKNOWN) { // provided a legacy type? return FlowInfo.POTENTIALLY_NULL; // -> use more specific info from the annotation } return nullStatus; }
Example 14
Source File: CastExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public TypeBinding resolveType(BlockScope scope) { // compute a new constant if the cast is effective this.constant = Constant.NotAConstant; this.implicitConversion = TypeIds.T_undefined; boolean exprContainCast = false; TypeBinding castType = this.resolvedType = this.type.resolveType(scope); if (scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8) { this.expression.setExpressionContext(CASTING_CONTEXT); if (this.expression instanceof FunctionalExpression) { this.expression.setExpectedType(this.resolvedType); this.bits |= ASTNode.DisableUnnecessaryCastCheck; } } if (this.expression instanceof CastExpression) { this.expression.bits |= ASTNode.DisableUnnecessaryCastCheck; exprContainCast = true; } TypeBinding expressionType = this.expression.resolveType(scope); if (this.expression instanceof MessageSend) { MessageSend messageSend = (MessageSend) this.expression; MethodBinding methodBinding = messageSend.binding; if (methodBinding != null && methodBinding.isPolymorphic()) { messageSend.binding = scope.environment().updatePolymorphicMethodReturnType((PolymorphicMethodBinding) methodBinding, castType); if (TypeBinding.notEquals(expressionType, castType)) { expressionType = castType; this.bits |= ASTNode.DisableUnnecessaryCastCheck; } } } if (castType != null) { if (expressionType != null) { boolean nullAnnotationMismatch = scope.compilerOptions().isAnnotationBasedNullAnalysisEnabled && NullAnnotationMatching.analyse(castType, expressionType, -1).isAnyMismatch(); boolean isLegal = checkCastTypesCompatibility(scope, castType, expressionType, this.expression); if (isLegal) { this.expression.computeConversion(scope, castType, expressionType); if ((this.bits & ASTNode.UnsafeCast) != 0) { // unsafe cast if (scope.compilerOptions().reportUnavoidableGenericTypeProblems || !(expressionType.isRawType() && this.expression.forcedToBeRaw(scope.referenceContext()))) { scope.problemReporter().unsafeCast(this, scope); } } else if (nullAnnotationMismatch) { // report null annotation issue at medium priority scope.problemReporter().unsafeNullnessCast(this, scope); } else { if (castType.isRawType() && scope.compilerOptions().getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore){ scope.problemReporter().rawTypeReference(this.type, castType); } if ((this.bits & (ASTNode.UnnecessaryCast|ASTNode.DisableUnnecessaryCastCheck)) == ASTNode.UnnecessaryCast) { // unnecessary cast if (!isIndirectlyUsed()) // used for generic type inference or boxing ? scope.problemReporter().unnecessaryCast(this); } } } else { // illegal cast if ((castType.tagBits & TagBits.HasMissingType) == 0) { // no complaint if secondary error scope.problemReporter().typeCastError(this, castType, expressionType); } this.bits |= ASTNode.DisableUnnecessaryCastCheck; // disable further secondary diagnosis } } this.resolvedType = castType.capture(scope, this.sourceEnd); if (exprContainCast) { checkNeedForCastCast(scope, this); } } return this.resolvedType; }
Example 15
Source File: MessageSend.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Find the method binding; * if this.innersNeedUpdate allow for two attempts where the first round may stop * after applicability checking (18.5.1) to include more information into the final * invocation type inference (18.5.2). */ protected void findMethodBinding(BlockScope scope, TypeBinding[] argumentTypes) { this.binding = this.receiver.isImplicitThis() ? scope.getImplicitMethod(this.selector, argumentTypes, this) : scope.getMethod(this.actualReceiverType, this.selector, argumentTypes, this); resolvePolyExpressionArguments(this, this.binding, argumentTypes, scope); /* There are embedded assumptions in the JLS8 type inference scheme that a successful solution of the type equations results in an applicable method. This appears to be a tenuous assumption, at least one not made by the JLS7 engine or the reference compiler and there are cases where this assumption would appear invalid: See https://bugs.eclipse.org/bugs/show_bug.cgi?id=426537, where we allow certain compatibility constrains around raw types to be violated. Here, we filter out such inapplicable methods with raw type usage that may have sneaked past overload resolution and type inference, playing the devils advocate, blaming the invocations with raw arguments that should not go blameless. At this time this is in the nature of a point fix and is not a general solution which needs to come later (that also includes AE, QAE and ECC) */ final CompilerOptions compilerOptions = scope.compilerOptions(); if (compilerOptions.sourceLevel >= ClassFileConstants.JDK1_8 && this.binding instanceof ParameterizedGenericMethodBinding && this.binding.isValidBinding()) { if (!compilerOptions.postResolutionRawTypeCompatibilityCheck) return; ParameterizedGenericMethodBinding pgmb = (ParameterizedGenericMethodBinding) this.binding; InferenceContext18 ctx = getInferenceContext(pgmb); if (ctx == null || ctx.stepCompleted < InferenceContext18.BINDINGS_UPDATED) return; int length = pgmb.typeArguments == null ? 0 : pgmb.typeArguments.length; boolean sawRawType = false; for (int i = 0; i < length; i++) { /* Must check compatibility against capture free method. Formal parameters cannot have captures, but our machinery is not up to snuff to construct a PGMB without captures at the moment - for one thing ITCB does not support uncapture() yet, for another, INTERSECTION_CAST_TYPE does not appear fully hooked up into isCompatibleWith and isEquivalent to everywhere. At the moment, bail out if we see capture. */ if (pgmb.typeArguments[i].isCapture()) return; if (pgmb.typeArguments[i].isRawType()) sawRawType = true; } if (!sawRawType) return; length = this.arguments == null ? 0 : this.arguments.length; if (length == 0) return; TypeBinding [] finalArgumentTypes = new TypeBinding[length]; for (int i = 0; i < length; i++) { TypeBinding finalArgumentType = this.arguments[i].resolvedType; if (finalArgumentType == null || !finalArgumentType.isValidBinding()) // already sided with the devil. return; finalArgumentTypes[i] = finalArgumentType; } if (scope.parameterCompatibilityLevel(this.binding, finalArgumentTypes, false) == Scope.NOT_COMPATIBLE) this.binding = new ProblemMethodBinding(this.binding.original(), this.binding.selector, finalArgumentTypes, ProblemReasons.NotFound); } }
Example 16
Source File: SourceTypeBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public FieldBinding resolveTypeFor(FieldBinding field) { if (!isPrototype()) return this.prototype.resolveTypeFor(field); if ((field.modifiers & ExtraCompilerModifiers.AccUnresolved) == 0) return field; long sourceLevel = this.scope.compilerOptions().sourceLevel; if (sourceLevel >= ClassFileConstants.JDK1_5) { if ((field.getAnnotationTagBits() & TagBits.AnnotationDeprecated) != 0) field.modifiers |= ClassFileConstants.AccDeprecated; } if (isViewedAsDeprecated() && !field.isDeprecated()) field.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly; if (hasRestrictedAccess()) field.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess; FieldDeclaration[] fieldDecls = this.scope.referenceContext.fields; int length = fieldDecls == null ? 0 : fieldDecls.length; for (int f = 0; f < length; f++) { if (fieldDecls[f].binding != field) continue; MethodScope initializationScope = field.isStatic() ? this.scope.referenceContext.staticInitializerScope : this.scope.referenceContext.initializerScope; FieldBinding previousField = initializationScope.initializedField; try { initializationScope.initializedField = field; FieldDeclaration fieldDecl = fieldDecls[f]; TypeBinding fieldType = fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT ? initializationScope.environment().convertToRawType(this, false /*do not force conversion of enclosing types*/) // enum constant is implicitly of declaring enum type : fieldDecl.type.resolveType(initializationScope, true /* check bounds*/); field.type = fieldType; field.modifiers &= ~ExtraCompilerModifiers.AccUnresolved; if (fieldType == null) { fieldDecl.binding = null; return null; } if (fieldType == TypeBinding.VOID) { this.scope.problemReporter().variableTypeCannotBeVoid(fieldDecl); fieldDecl.binding = null; return null; } if (fieldType.isArrayType() && ((ArrayBinding) fieldType).leafComponentType == TypeBinding.VOID) { this.scope.problemReporter().variableTypeCannotBeVoidArray(fieldDecl); fieldDecl.binding = null; return null; } if ((fieldType.tagBits & TagBits.HasMissingType) != 0) { field.tagBits |= TagBits.HasMissingType; } TypeBinding leafType = fieldType.leafComponentType(); if (leafType instanceof ReferenceBinding && (((ReferenceBinding)leafType).modifiers & ExtraCompilerModifiers.AccGenericSignature) != 0) { field.modifiers |= ExtraCompilerModifiers.AccGenericSignature; } if (sourceLevel >= ClassFileConstants.JDK1_8) { Annotation [] annotations = fieldDecl.annotations; if (annotations != null && annotations.length != 0) { ASTNode.copySE8AnnotationsToType(initializationScope, field, annotations, fieldDecl.getKind() != AbstractVariableDeclaration.ENUM_CONSTANT); // type annotation is illegal on enum constant } Annotation.isTypeUseCompatible(fieldDecl.type, this.scope, annotations); } // apply null default: if (this.environment.globalOptions.isAnnotationBasedNullAnalysisEnabled) { // TODO(SH): different strategy for 1.8, or is "repair" below enough? if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { // enum constants neither have a type declaration nor can they be null field.tagBits |= TagBits.AnnotationNonNull; } else { if (hasNonNullDefaultFor(DefaultLocationField, sourceLevel >= ClassFileConstants.JDK1_8)) { field.fillInDefaultNonNullness(fieldDecl, initializationScope); } // validate null annotation: if (!this.scope.validateNullAnnotation(field.tagBits, fieldDecl.type, fieldDecl.annotations)) field.tagBits &= ~TagBits.AnnotationNullMASK; } } } finally { initializationScope.initializedField = previousField; } return field; } return null; // should never reach this point }
Example 17
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; } } }
Example 18
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 19
Source File: CodeSnippetClassFile.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * INTERNAL USE-ONLY * Request the creation of a ClassFile compatible representation of a problematic type * * @param typeDeclaration org.eclipse.jdt.internal.compiler.ast.TypeDeclaration * @param unitResult org.eclipse.jdt.internal.compiler.CompilationUnitResult */ public static void createProblemType(TypeDeclaration typeDeclaration, CompilationResult unitResult) { SourceTypeBinding typeBinding = typeDeclaration.binding; ClassFile classFile = new CodeSnippetClassFile(typeBinding, null, true); // inner attributes if (typeBinding.hasMemberTypes()) { // see bug 180109 ReferenceBinding[] members = typeBinding.memberTypes; for (int i = 0, l = members.length; i < l; i++) classFile.recordInnerClasses(members[i]); } // TODO (olivier) handle cases where a field cannot be generated (name too long) // TODO (olivier) handle too many methods // inner attributes if (typeBinding.isNestedType()) { classFile.recordInnerClasses(typeBinding); } TypeVariableBinding[] typeVariables = typeBinding.typeVariables(); for (int i = 0, max = typeVariables.length; i < max; i++) { TypeVariableBinding typeVariableBinding = typeVariables[i]; if ((typeVariableBinding.tagBits & TagBits.ContainsNestedTypeReferences) != 0) { Util.recordNestedType(classFile, typeVariableBinding); } } // add its fields FieldBinding[] fields = typeBinding.fields(); if ((fields != null) && (fields != Binding.NO_FIELDS)) { classFile.addFieldInfos(); } else { // we have to set the number of fields to be equals to 0 classFile.contents[classFile.contentsOffset++] = 0; classFile.contents[classFile.contentsOffset++] = 0; } // leave some space for the methodCount classFile.setForMethodInfos(); // add its user defined methods int problemsLength; CategorizedProblem[] problems = unitResult.getErrors(); if (problems == null) { problems = new CategorizedProblem[0]; } CategorizedProblem[] problemsCopy = new CategorizedProblem[problemsLength = problems.length]; System.arraycopy(problems, 0, problemsCopy, 0, problemsLength); AbstractMethodDeclaration[] methodDecls = typeDeclaration.methods; boolean abstractMethodsOnly = false; if (methodDecls != null) { if (typeBinding.isInterface()) { if (typeBinding.scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_8) abstractMethodsOnly = true; // We generate a clinit which contains all the problems, since we may not be able to generate problem methods (< 1.8) and problem constructors (all levels). classFile.addProblemClinit(problemsCopy); } for (int i = 0, length = methodDecls.length; i < length; i++) { AbstractMethodDeclaration methodDecl = methodDecls[i]; MethodBinding method = methodDecl.binding; if (method == null) continue; if (abstractMethodsOnly) { method.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract; } if (method.isConstructor()) { if (typeBinding.isInterface()) continue; classFile.addProblemConstructor(methodDecl, method, problemsCopy); } else if (method.isAbstract()) { classFile.addAbstractMethod(methodDecl, method); } else { classFile.addProblemMethod(methodDecl, method, problemsCopy); } } // add abstract methods classFile.addDefaultAbstractMethods(); } // propagate generation of (problem) member types if (typeDeclaration.memberTypes != null) { for (int i = 0, max = typeDeclaration.memberTypes.length; i < max; i++) { TypeDeclaration memberType = typeDeclaration.memberTypes[i]; if (memberType.binding != null) { ClassFile.createProblemType(memberType, unitResult); } } } classFile.addAttributes(); unitResult.record(typeBinding.constantPoolName(), classFile); }
Example 20
Source File: MethodVerifier15.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
void checkInheritedMethods(MethodBinding[] methods, int length, boolean[] isOverridden, boolean[] isInherited) { boolean continueInvestigation = true; MethodBinding concreteMethod = null; MethodBinding abstractSuperClassMethod = null; boolean playingTrump = false; // invariant: playingTrump => (concreteMethod == null) for (int i = 0; i < length; i++) { if (!methods[i].declaringClass.isInterface() && TypeBinding.notEquals(methods[i].declaringClass, this.type) && methods[i].isAbstract()) { abstractSuperClassMethod = methods[i]; break; } } for (int i = 0; i < length; i++) { // methods not inherited as of 8.4.8 cannot create a name clash, // but could still cause errors against return types etc. (below) if (isInherited[i] && !methods[i].isAbstract()) { // 8.4.8.4 defines an exception for default methods if // (a) there exists an abstract method declared in a superclass of C and inherited by C // (b) that is override-equivalent with the two methods. if (methods[i].isDefaultMethod() && abstractSuperClassMethod != null // condition (a) && areParametersEqual(abstractSuperClassMethod, methods[i]) // condition (b)... && concreteMethod == null) { // skip, class method trumps this default method (concreteMethod remains null) playingTrump = true; } else { playingTrump = false; if (concreteMethod != null) { // re-checking compatibility is needed for https://bugs.eclipse.org/346029 if (isOverridden[i] && areMethodsCompatible(concreteMethod, methods[i])) { continue; } // https://bugs.eclipse.org/195802 with https://bugs.eclipse.org/410325 // If a replace method (from findReplacedMethod()) is the rawified version of another // don't count this as duplicates: // (Not asking ParameterizedGenericMethodBinding.isRawMethod(), // because that is true only for methods of a RawTypeBinding, // but here we look for rawness regarding the method's type variables). if (TypeBinding.equalsEquals(concreteMethod.declaringClass, methods[i].declaringClass) && concreteMethod.typeVariables.length != methods[i].typeVariables.length) { if (concreteMethod.typeVariables == Binding.NO_TYPE_VARIABLES && concreteMethod.original() == methods[i]) continue; if (methods[i].typeVariables == Binding.NO_TYPE_VARIABLES && methods[i].original() == concreteMethod) continue; } problemReporter().duplicateInheritedMethods(this.type, concreteMethod, methods[i], this.environment.globalOptions.sourceLevel >= ClassFileConstants.JDK1_8); continueInvestigation = false; } concreteMethod = methods[i]; } } } if (continueInvestigation) { if (playingTrump) { // multiple abstract & default methods are OK on this branch, but then the class must be declared abstract: if (!this.type.isAbstract()) { problemReporter().abstractMethodMustBeImplemented(this.type, abstractSuperClassMethod); return; } } else { if (concreteMethod != null && concreteMethod.isDefaultMethod()) { if (this.environment.globalOptions.complianceLevel >= ClassFileConstants.JDK1_8) { if (!checkInheritedDefaultMethods(methods, length)) return; } } } super.checkInheritedMethods(methods, length, isOverridden, isInherited); } }