/** * Answer the problem reporter to use for raising new problems. * * Note that as a side-effect, this updates the current reference context * (unit, type or method) in case the problem handler decides it is necessary * to abort. */ public ProblemReporter problemReporter() { MethodScope outerMethodScope; if ((outerMethodScope = outerMostMethodScope()) == this) { ProblemReporter problemReporter = referenceCompilationUnit().problemReporter; problemReporter.referenceContext = this.referenceContext; return problemReporter; } return outerMethodScope.problemReporter(); }
public void resolve(ClassScope classScope) { this.scope = new MethodScope(classScope, classScope.referenceContext, true); }
public CompilationUnitDeclaration getCompilationUnitDeclaration() { if (this.scope != null) { return this.scope.compilationUnitScope().referenceContext; } return null; }
SourceTypeBinding declaringClass = referenceType().binding; int modifiers = method.modifiers | ExtraCompilerModifiers.AccUnresolved; if (method.isConstructor()) { modifiers |= ExtraCompilerModifiers.AccIsDefaultConstructor; method.binding = new MethodBinding(modifiers, null, null, declaringClass); checkAndSetModifiersForConstructor(method.binding); } else { if (declaringClass.isInterface()) // interface or annotation type method.binding = new MethodBinding(modifiers, method.selector, null, null, null, declaringClass); checkAndSetModifiersForMethod(method.binding); if (argLength > 0 && compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) { if (argTypes[--argLength].isVarArgs()) method.binding.modifiers |= ClassFileConstants.AccVarargs; while (--argLength >= 0) { if (argTypes[argLength].isVarArgs()) problemReporter().illegalVararg(argTypes[argLength], method); if (typeParameters == null || compilerOptions().sourceLevel < ClassFileConstants.JDK1_5) { method.binding.typeVariables = Binding.NO_TYPE_VARIABLES; } else { method.binding.typeVariables = createTypeVariables(typeParameters, method.binding); method.binding.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
Binding existingVariable = scope.getBinding(this.name, Binding.VARIABLE, this, false /*do not resolve hidden field*/); if (existingVariable != null && existingVariable.isValidBinding()){ final boolean localExists = existingVariable instanceof LocalVariableBinding; if (localExists && this.hiddenVariableDepth == 0) { if ((this.bits & ASTNode.ShadowsOuterLocal) != 0 && scope.isLambdaSubscope()) { scope.problemReporter().lambdaRedeclaresArgument(this); } else { scope.problemReporter().redefineArgument(this); if (scope.isInsideConstructor()) { isSpecialArgument = true; // constructor argument } else { AbstractMethodDeclaration methodDecl = scope.referenceMethod(); if (methodDecl != null && CharOperation.prefixEquals(SET, methodDecl.selector)) { isSpecialArgument = true; // setter argument scope.problemReporter().localVariableHiding(this, existingVariable, isSpecialArgument); scope.addLocalVariable(this.binding); this.binding.useFlag = used ? LocalVariableBinding.USED : LocalVariableBinding.UNUSED; return newTypeBinding;
&& this.binding.isOrEnclosedByPrivateType())) { if (!classScope.referenceCompilationUnit().compilationResult.hasSyntaxError) { this.scope.problemReporter().unusedPrivateMethod(this); !this.scope.referenceCompilationUnit().compilationResult.hasSyntaxError) { for (int i = 0, length = this.typeParameters.length; i < length; ++i) { TypeParameter typeParameter = this.typeParameters[i]; if ((typeParameter.binding.modifiers & ExtraCompilerModifiers.AccLocallyUsed) == 0) { this.scope.problemReporter().unusedTypeParameter(typeParameter); boolean enableSyntacticNullAnalysisForFields = this.scope.compilerOptions().enableSyntacticNullAnalysisForFields; int complaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) == 0 ? Statement.NOT_COMPLAINED : Statement.COMPLAINED_FAKE_REACHABLE; for (int i = 0, count = this.statements.length; i < count; i++) { this.scope.problemReporter().shouldReturn(returnTypeBinding, this); this.scope.checkUnusedParameters(this.binding); this.scope.problemReporter().methodCanBeDeclaredStatic(this); } else { this.scope.problemReporter().methodCanBePotentiallyDeclaredStatic(this); this.scope.checkUnclosedCloseables(flowInfo, null, null/*don't report against a specific location*/, null); } catch (AbortMethod e) { this.ignoreFurtherInvestigation = true;
ClassScope classScope = initializationScope.enclosingClassScope(); if (!existingVariable.canBeSeenBy(declaringType, this, initializationScope)) break checkHidingSuperField; // keep checking outer scenario initializationScope.problemReporter().fieldHiding(this, existingVariable); break checkHiding; // already found a matching field initializationScope.problemReporter().fieldHiding(this, existingVariable); && initializationScope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) { initializationScope.problemReporter().missingDeprecatedAnnotationForField(this); initializationScope.compilationUnitScope().recordTypeConversion(fieldType, initializationType); if (this.initialization.isConstantValueOfTypeAssignableToType(initializationType, fieldType) || initializationType.isCompatibleWith(fieldType, classScope)) { this.initialization.computeConversion(initializationScope, fieldType, initializationType); if (initializationType.needsUncheckedConversion(fieldType)) { initializationScope.problemReporter().unsafeTypeConversion(this.initialization, initializationType, fieldType); if ((fieldType.tagBits & TagBits.HasMissingType) == 0) { initializationScope.problemReporter().typeMismatchError(initializationType, fieldType, this.initialization, null); initializationScope.problemReporter().assignmentHasNoEffect(this, this.name);
public void resolveJavadoc() { if (this.binding == null) return; if (this.javadoc != null) { this.javadoc.resolve(this.scope); return; } if (this.binding.declaringClass != null && !this.binding.declaringClass.isLocalType()) { // Set javadoc visibility int javadocVisibility = this.binding.modifiers & ExtraCompilerModifiers.AccVisibilityMASK; ClassScope classScope = this.scope.classScope(); ProblemReporter reporter = this.scope.problemReporter(); int severity = reporter.computeSeverity(IProblem.JavadocMissing); if (severity != ProblemSeverities.Ignore) { if (classScope != null) { javadocVisibility = Util.computeOuterMostVisibility(classScope.referenceType(), javadocVisibility); } int javadocModifiers = (this.binding.modifiers & ~ExtraCompilerModifiers.AccVisibilityMASK) | javadocVisibility; reporter.javadocMissing(this.sourceStart, this.sourceEnd, severity, javadocModifiers); } } }
/** * Answer true if the receiver is suitable for assigning final blank fields. * in other words, it is inside an initializer, a constructor or a clinit */ public final boolean allowBlankFinalFieldAssignment(FieldBinding binding) { if (TypeBinding.notEquals(enclosingReceiverType(), binding.declaringClass)) return false; MethodScope methodScope = methodScope(); if (methodScope.isStatic != binding.isStatic()) return false; if (methodScope.isLambdaScope()) return false; return methodScope.isInsideInitializer() // inside initializer || ((AbstractMethodDeclaration) methodScope.referenceContext).isInitializationMethod(); // inside constructor or clinit }
/** * Returns true if the context requires to check initialization of final blank fields. * in other words, it is inside an initializer, a constructor or a clinit */ public final boolean needBlankFinalFieldInitializationCheck(FieldBinding binding) { boolean isStatic = binding.isStatic(); ReferenceBinding fieldDeclaringClass = binding.declaringClass; // loop in enclosing context, until reaching the field declaring context MethodScope methodScope = namedMethodScope(); while (methodScope != null) { if (methodScope.isStatic != isStatic) return false; if (!methodScope.isInsideInitializer() // inside initializer && !((AbstractMethodDeclaration) methodScope.referenceContext).isInitializationMethod()) { // inside constructor or clinit return false; // found some non-initializer context } ReferenceBinding enclosingType = methodScope.enclosingReceiverType(); if (TypeBinding.equalsEquals(enclosingType, fieldDeclaringClass)) { return true; // found the field context, no need to check any further } if (!enclosingType.erasure().isAnonymousType()) { return false; // only check inside anonymous type } methodScope = methodScope.enclosingMethodScope().namedMethodScope(); } return false; }
/** * Answer the problem reporter to use for raising new problems. * * Note that as a side-effect, this updates the current reference context * (unit, type or method) in case the problem handler decides it is necessary * to abort. */ public ProblemReporter problemReporter() { ProblemReporter problemReporter = referenceCompilationUnit().problemReporter; problemReporter.referenceContext = this.referenceContext; return problemReporter; }
/** * Returns true if the context requires to check initialization of final blank fields. * in other words, it is inside an initializer, a constructor or a clinit */ public final boolean needBlankFinalFieldInitializationCheck(FieldBinding binding) { boolean isStatic = binding.isStatic(); ReferenceBinding fieldDeclaringClass = binding.declaringClass; // loop in enclosing context, until reaching the field declaring context MethodScope methodScope = methodScope(); while (methodScope != null) { if (methodScope.isStatic != isStatic) return false; if (!methodScope.isInsideInitializer() // inside initializer && !((AbstractMethodDeclaration) methodScope.referenceContext).isInitializationMethod()) { // inside constructor or clinit return false; // found some non-initializer context } ReferenceBinding enclosingType = methodScope.enclosingReceiverType(); if (enclosingType == fieldDeclaringClass) { return true; // found the field context, no need to check any further } if (!enclosingType.erasure().isAnonymousType()) { return false; // only check inside anonymous type } methodScope = methodScope.enclosingMethodScope(); } return false; }
this.scope.problemReporter().unusedPrivateConstructor(this); this.scope.problemReporter().recursiveConstructorInvocation(this.constructorCall); && field.isFinal() && (!flowInfo.isDefinitelyAssigned(fields[i]))) { this.scope.problemReporter().uninitializedBlankFinalField( field, ((this.bits & ASTNode.IsDefaultConstructor) != 0) ? (ASTNode) this.scope.referenceType() : this); this.scope.checkUnusedParameters(this.binding); } catch (AbortMethod e) { this.ignoreFurtherInvestigation = true;
&& this.binding.isOrEnclosedByPrivateType())) { if (!classScope.referenceCompilationUnit().compilationResult.hasSyntaxError) { this.scope.problemReporter().unusedPrivateMethod(this); this.scope.problemReporter().shouldReturn(returnTypeBinding, this); this.scope.checkUnusedParameters(this.binding); this.scope.problemReporter().methodCanBeDeclaredStatic(this); } else { this.scope.problemReporter().methodCanBePotentiallyDeclaredStatic(this); this.scope.checkUnclosedCloseables(flowInfo, null, null/*don't report against a specific location*/, null); } catch (AbortMethod e) { this.ignoreFurtherInvestigation = true;
&& this.binding.isOrEnclosedByPrivateType())) { if (!classScope.referenceCompilationUnit().compilationResult.hasSyntaxError) { this.scope.problemReporter().unusedPrivateMethod(this); this.scope.problemReporter().shouldReturn(returnTypeBinding, this); this.scope.checkUnusedParameters(this.binding); } catch (AbortMethod e) { this.ignoreFurtherInvestigation = true;
public void find( char[] startWith, AbstractMethodDeclaration methodDeclaration, int from, char[][] discouragedNames, UnresolvedReferenceNameRequestor nameRequestor) { MethodDeclaration fakeMethod = this.findAfter(startWith, methodDeclaration.scope, from, methodDeclaration.bodyEnd, MAX_LINE_COUNT, false, discouragedNames, nameRequestor); if (fakeMethod != null) fakeMethod.traverse(this, methodDeclaration.scope.classScope()); }
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); } return flowInfo; }
/** * Answer true if the receiver is suitable for assigning final blank fields. * in other words, it is inside an initializer, a constructor or a clinit */ public final boolean allowBlankFinalFieldAssignment(FieldBinding binding) { if (enclosingReceiverType() != binding.declaringClass) return false; MethodScope methodScope = methodScope(); if (methodScope.isStatic != binding.isStatic()) return false; return methodScope.isInsideInitializer() // inside initializer || ((AbstractMethodDeclaration) methodScope.referenceContext).isInitializationMethod(); // inside constructor or clinit }
private void processSuperCallThisArgs(ReferenceBinding superClass, JMethodCall call, JExpression qualifier, Expression qualification) { // Explicit super calls can only happend inside constructors assert curMethod.scope.isInsideConstructor(); if (superClass.syntheticEnclosingInstanceTypes() != null) { // there can only be ONE immediate enclosing instance. assert superClass.syntheticEnclosingInstanceTypes().length == 1; ReferenceBinding targetType = superClass.syntheticEnclosingInstanceTypes()[0]; if (qualification != null) { // Outer object is the qualifier. call.addArg(qualifier); } else { // Get implicit outer object. call.addArg(makeThisReference(call.getSourceInfo(), targetType, false, curMethod.scope)); } } }
SourceTypeBinding declaringClass = referenceType().binding; int modifiers = method.modifiers | ExtraCompilerModifiers.AccUnresolved; if (method.isConstructor()) { modifiers |= ExtraCompilerModifiers.AccIsDefaultConstructor; method.binding = new MethodBinding(modifiers, null, null, declaringClass); checkAndSetModifiersForConstructor(method.binding); } else { if (declaringClass.isInterface()) // interface or annotation type method.binding = new MethodBinding(modifiers, method.selector, null, null, null, declaringClass); checkAndSetModifiersForMethod(method.binding); if (argLength > 0 && compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) { if (argTypes[--argLength].isVarArgs()) method.binding.modifiers |= ClassFileConstants.AccVarargs; while (--argLength >= 0) { if (argTypes[argLength].isVarArgs()) problemReporter().illegalVararg(argTypes[argLength], method); method.binding.typeVariables = Binding.NO_TYPE_VARIABLES; } else { method.binding.typeVariables = createTypeVariables(typeParameters, method.binding); method.binding.modifiers |= ExtraCompilerModifiers.AccGenericSignature;