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); } } } }
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); } } } }
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); } } } }
private void analyzeExceptions() { ExceptionHandlingFlowContext ehfc; CompilerOptions compilerOptions = this.scope.compilerOptions(); boolean oldAnalyseResources = compilerOptions.analyseResourceLeaks; compilerOptions.analyseResourceLeaks = false; try { this.body.analyseCode(this.scope, ehfc = new ExceptionInferenceFlowContext(null, this, Binding.NO_EXCEPTIONS, null, this.scope, FlowInfo.DEAD_END), UnconditionalFlowInfo.fakeInitializedFlowInfo(this.scope.outerMostMethodScope().analysisIndex, this.scope.referenceType().maxFieldCount)); this.thrownExceptions = ehfc.extendedExceptions == null ? Collections.emptySet() : new HashSet<TypeBinding>(ehfc.extendedExceptions); } catch (Exception e) { // drop silently. } finally { compilerOptions.analyseResourceLeaks = oldAnalyseResources; } } @Override
private void analyzeExceptions() { ExceptionHandlingFlowContext ehfc; CompilerOptions compilerOptions = this.scope.compilerOptions(); boolean oldAnalyseResources = compilerOptions.analyseResourceLeaks; compilerOptions.analyseResourceLeaks = false; try { this.body.analyseCode(this.scope, ehfc = new ExceptionInferenceFlowContext(null, this, Binding.NO_EXCEPTIONS, null, this.scope, FlowInfo.DEAD_END), UnconditionalFlowInfo.fakeInitializedFlowInfo(this.scope.outerMostMethodScope().analysisIndex, this.scope.referenceType().maxFieldCount)); this.thrownExceptions = ehfc.extendedExceptions == null ? Collections.emptySet() : new HashSet<TypeBinding>(ehfc.extendedExceptions); } catch (Exception e) { // drop silently. } finally { compilerOptions.analyseResourceLeaks = oldAnalyseResources; } } public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, final FlowInfo flowInfo) {
public void checkUnusedParameters(MethodBinding method) { if (method.isAbstract() || (method.isImplementing() && !compilerOptions().reportUnusedParameterWhenImplementingAbstract) || (method.isOverriding() && !method.isImplementing() && !compilerOptions().reportUnusedParameterWhenOverridingConcrete) || method.isMain()) { // do not want to check return; } for (int i = 0, maxLocals = this.localIndex; i < maxLocals; i++) { LocalVariableBinding local = this.locals[i]; if (local == null || ((local.tagBits & TagBits.IsArgument) == 0)) { break; // done with arguments } if (local.useFlag == LocalVariableBinding.UNUSED && // do not report fake used variable ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable problemReporter().unusedArgument(local.declaration); } } }
public void checkUnusedParameters(MethodBinding method) { if (method.isAbstract() || (method.isImplementing() && !compilerOptions().reportUnusedParameterWhenImplementingAbstract) || (method.isOverriding() && !method.isImplementing() && !compilerOptions().reportUnusedParameterWhenOverridingConcrete) || method.isMain()) { // do not want to check return; } for (int i = 0, maxLocals = this.localIndex; i < maxLocals; i++) { LocalVariableBinding local = this.locals[i]; if (local == null || ((local.tagBits & TagBits.IsArgument) == 0)) { break; // done with arguments } if (local.useFlag == LocalVariableBinding.UNUSED && // do not report fake used variable ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable problemReporter().unusedArgument(local.declaration); } } }
public void checkUnusedParameters(MethodBinding method) { if (method.isAbstract() || (method.isImplementing() && !compilerOptions().reportUnusedParameterWhenImplementingAbstract) || (method.isOverriding() && !method.isImplementing() && !compilerOptions().reportUnusedParameterWhenOverridingConcrete) || method.isMain()) { // do not want to check return; } for (int i = 0, maxLocals = this.localIndex; i < maxLocals; i++) { LocalVariableBinding local = this.locals[i]; if (local == null || ((local.tagBits & TagBits.IsArgument) == 0)) { break; // done with arguments } if (local.useFlag == LocalVariableBinding.UNUSED && // do not report fake used variable ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable problemReporter().unusedArgument(local.declaration); } } }
public void checkUnusedParameters(MethodBinding method) { if (method.isAbstract() || (method.isImplementing() && !compilerOptions().reportUnusedParameterWhenImplementingAbstract) || (method.isOverriding() && !method.isImplementing() && !compilerOptions().reportUnusedParameterWhenOverridingConcrete) || method.isMain()) { // do not want to check return; } for (int i = 0, maxLocals = this.localIndex; i < maxLocals; i++) { LocalVariableBinding local = this.locals[i]; if (local == null || ((local.tagBits & TagBits.IsArgument) == 0)) { break; // done with arguments } if (local.useFlag == LocalVariableBinding.UNUSED && // do not report fake used variable ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable problemReporter().unusedArgument(local.declaration); } } }
public void checkUnusedParameters(MethodBinding method) { if (method.isAbstract() || (method.isImplementing() && !compilerOptions().reportUnusedParameterWhenImplementingAbstract) || (method.isOverriding() && !method.isImplementing() && !compilerOptions().reportUnusedParameterWhenOverridingConcrete) || method.isMain()) { // do not want to check return; } for (int i = 0, maxLocals = this.localIndex; i < maxLocals; i++) { LocalVariableBinding local = this.locals[i]; if (local == null || ((local.tagBits & TagBits.IsArgument) == 0)) { break; // done with arguments } if (local.useFlag == LocalVariableBinding.UNUSED && // do not report fake used variable ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable problemReporter().unusedArgument(local.declaration); } } }
public void checkUnusedParameters(MethodBinding method) { if (method.isAbstract() || (method.isImplementing() && !compilerOptions().reportUnusedParameterWhenImplementingAbstract) || (method.isOverriding() && !method.isImplementing() && !compilerOptions().reportUnusedParameterWhenOverridingConcrete) || method.isMain()) { // do not want to check return; } for (int i = 0, maxLocals = this.localIndex; i < maxLocals; i++) { LocalVariableBinding local = this.locals[i]; if (local == null || ((local.tagBits & TagBits.IsArgument) == 0)) { break; // done with arguments } if (local.useFlag == LocalVariableBinding.UNUSED && // do not report fake used variable ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable problemReporter().unusedArgument(local.declaration); } } }
public void checkUnusedParameters(MethodBinding method) { if (method.isAbstract() || (method.isImplementing() && !compilerOptions().reportUnusedParameterWhenImplementingAbstract) || (method.isOverriding() && !method.isImplementing() && !compilerOptions().reportUnusedParameterWhenOverridingConcrete) || method.isMain()) { // do not want to check return; } for (int i = 0, maxLocals = this.localIndex; i < maxLocals; i++) { LocalVariableBinding local = this.locals[i]; if (local == null || ((local.tagBits & TagBits.IsArgument) == 0)) { break; // done with arguments } if (local.useFlag == LocalVariableBinding.UNUSED && // do not report fake used variable ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable problemReporter().unusedArgument(local.declaration); } } }
public void checkUnusedParameters(MethodBinding method) { if (method.isAbstract() || (method.isImplementing() && !compilerOptions().reportUnusedParameterWhenImplementingAbstract) || (method.isOverriding() && !method.isImplementing() && !compilerOptions().reportUnusedParameterWhenOverridingConcrete) || method.isMain()) { // do not want to check return; } for (int i = 0, maxLocals = this.localIndex; i < maxLocals; i++) { LocalVariableBinding local = this.locals[i]; if (local == null || ((local.tagBits & TagBits.IsArgument) == 0)) { break; // done with arguments } if (local.useFlag == LocalVariableBinding.UNUSED && // do not report fake used variable ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable problemReporter().unusedArgument(local.declaration); } } }
public void checkUnusedParameters(MethodBinding method) { if (method.isAbstract() || (method.isImplementing() && !compilerOptions().reportUnusedParameterWhenImplementingAbstract) || (method.isOverriding() && !method.isImplementing() && !compilerOptions().reportUnusedParameterWhenOverridingConcrete) || method.isMain()) { // do not want to check return; } for (int i = 0, maxLocals = this.localIndex; i < maxLocals; i++) { LocalVariableBinding local = this.locals[i]; if (local == null || ((local.tagBits & TagBits.IsArgument) == 0)) { break; // done with arguments } if (local.useFlag == LocalVariableBinding.UNUSED && // do not report fake used variable ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable problemReporter().unusedArgument(local.declaration); } } }
public void checkUnusedParameters(MethodBinding method) { if (method.isAbstract() || (method.isImplementing() && !compilerOptions().reportUnusedParameterWhenImplementingAbstract) || (method.isOverriding() && !method.isImplementing() && !compilerOptions().reportUnusedParameterWhenOverridingConcrete) || method.isMain()) { // do not want to check return; } for (int i = 0, maxLocals = this.localIndex; i < maxLocals; i++) { LocalVariableBinding local = this.locals[i]; if (local == null || ((local.tagBits & TagBits.IsArgument) == 0)) { break; // done with arguments } if (local.useFlag == LocalVariableBinding.UNUSED && // do not report fake used variable ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable problemReporter().unusedArgument(local.declaration); } } }
public void checkUnusedParameters(MethodBinding method) { if (method.isAbstract() || (method.isImplementing() && !compilerOptions().reportUnusedParameterWhenImplementingAbstract) || (method.isOverriding() && !method.isImplementing() && !compilerOptions().reportUnusedParameterWhenOverridingConcrete) || method.isMain()) { // do not want to check return; } for (int i = 0, maxLocals = this.localIndex; i < maxLocals; i++) { LocalVariableBinding local = this.locals[i]; if (local == null || ((local.tagBits & TagBits.IsArgument) == 0)) { break; // done with arguments } if (local.useFlag == LocalVariableBinding.UNUSED && // do not report fake used variable ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable problemReporter().unusedArgument(local.declaration); } } }
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) }
public void reset(LambdaExpression lambda, ClassFile targetClassFile) { init(targetClassFile); this.lambdaExpression = lambda; this.methodDeclaration = null; int[] lineSeparatorPositions2 = this.lineSeparatorPositions; if (lineSeparatorPositions2 != null) { int length = lineSeparatorPositions2.length; int lineSeparatorPositionsEnd = length - 1; int start = Util.getLineNumber(lambda.body().sourceStart, lineSeparatorPositions2, 0, lineSeparatorPositionsEnd); this.lineNumberStart = start; if (start > lineSeparatorPositionsEnd) { this.lineNumberEnd = start; } else { int end = Util.getLineNumber(lambda.body().sourceEnd, lineSeparatorPositions2, start - 1, lineSeparatorPositionsEnd); if (end >= lineSeparatorPositionsEnd) { end = length; } this.lineNumberEnd = end == 0 ? 1 : end; } } this.preserveUnusedLocals = lambda.scope.compilerOptions().preserveAllLocalVariables; initializeMaxLocals(lambda.binding); }
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) }
public void resolve(ClassScope upperScope) { if (this.binding == null) { this.ignoreFurtherInvestigation = true; } try { bindArguments(); bindThrownExceptions(); resolveJavadoc(); resolveAnnotations(this.scope, this.annotations, this.binding); resolveStatements(); // check @Deprecated annotation presence if (this.binding != null && (this.binding.getAnnotationTagBits() & TagBits.AnnotationDeprecated) == 0 && (this.binding.modifiers & ClassFileConstants.AccDeprecated) != 0 && this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) { this.scope.problemReporter().missingDeprecatedAnnotationForMethod(this); } } catch (AbortMethod e) { // ========= abort on fatal error ============= this.ignoreFurtherInvestigation = true; } }