use of org.eclipse.jdt.internal.compiler.flow.ExceptionHandlingFlowContext in project bazel-jdt-java-toolchain by salesforce.
the class Clinit method analyseCode.
public void analyseCode(ClassScope classScope, InitializationFlowContext staticInitializerFlowContext, FlowInfo flowInfo) {
if (this.ignoreFurtherInvestigation)
return;
try {
ExceptionHandlingFlowContext clinitContext = new ExceptionHandlingFlowContext(staticInitializerFlowContext.parent, this, Binding.NO_EXCEPTIONS, staticInitializerFlowContext, this.scope, FlowInfo.DEAD_END);
// check for missing returning path
if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) {
this.bits |= ASTNode.NeedFreeReturn;
}
// check missing blank final field initializations
flowInfo = flowInfo.mergedWith(staticInitializerFlowContext.initsOnReturn);
FieldBinding[] fields = this.scope.enclosingSourceType().fields();
for (int i = 0, count = fields.length; i < count; i++) {
FieldBinding field = fields[i];
if (field.isStatic()) {
if (!flowInfo.isDefinitelyAssigned(field)) {
if (field.isFinal()) {
this.scope.problemReporter().uninitializedBlankFinalField(field, this.scope.referenceType().declarationOf(field.original()));
// can complain against the field decl, since only one <clinit>
} else if (field.isNonNull()) {
this.scope.problemReporter().uninitializedNonNullField(field, this.scope.referenceType().declarationOf(field.original()));
}
}
}
}
// check static initializers thrown exceptions
staticInitializerFlowContext.checkInitializerExceptions(this.scope, clinitContext, flowInfo);
} catch (AbortMethod e) {
this.ignoreFurtherInvestigation = true;
}
}
use of org.eclipse.jdt.internal.compiler.flow.ExceptionHandlingFlowContext in project bazel-jdt-java-toolchain by salesforce.
the class LambdaExpression method analyzeExceptions.
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;
}
}
use of org.eclipse.jdt.internal.compiler.flow.ExceptionHandlingFlowContext in project bazel-jdt-java-toolchain by salesforce.
the class MethodDeclaration method analyseCode.
public void analyseCode(ClassScope classScope, FlowContext flowContext, FlowInfo flowInfo) {
// starting of the code analysis for methods
if (this.ignoreFurtherInvestigation)
return;
try {
if (this.binding == null)
return;
if (!this.binding.isUsed() && !this.binding.isAbstract()) {
if (this.binding.isPrivate() || (((this.binding.modifiers & (ExtraCompilerModifiers.AccOverriding | ExtraCompilerModifiers.AccImplementing)) == 0) && this.binding.isOrEnclosedByPrivateType())) {
if (!classScope.referenceCompilationUnit().compilationResult.hasSyntaxError) {
this.scope.problemReporter().unusedPrivateMethod(this);
}
}
}
// skip enum implicit methods
if (this.binding.declaringClass.isEnum() && (this.selector == TypeConstants.VALUES || this.selector == TypeConstants.VALUEOF))
return;
// may be in a non necessary <clinit> for innerclass with static final constant fields
if (this.binding.isAbstract() || this.binding.isNative())
return;
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=385780
if (this.typeParameters != null && !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);
}
}
}
ExceptionHandlingFlowContext methodContext = new ExceptionHandlingFlowContext(flowContext, this, this.binding.thrownExceptions, null, this.scope, FlowInfo.DEAD_END);
// nullity and mark as assigned
analyseArguments(classScope.environment(), flowInfo, this.arguments, this.binding);
if (this.binding.declaringClass instanceof MemberTypeBinding && !this.binding.declaringClass.isStatic()) {
// method of a non-static member type can't be static.
this.bits &= ~ASTNode.CanBeStatic;
}
// propagate to statements
if (this.statements != null) {
CompilerOptions compilerOptions = this.scope.compilerOptions();
boolean enableSyntacticNullAnalysisForFields = 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++) {
Statement stat = this.statements[i];
if ((complaintLevel = stat.complainIfUnreachable(flowInfo, this.scope, complaintLevel, true)) < Statement.COMPLAINED_UNREACHABLE) {
flowInfo = stat.analyseCode(this.scope, methodContext, flowInfo);
}
if (enableSyntacticNullAnalysisForFields) {
methodContext.expireNullCheckedFieldInfo();
}
if (compilerOptions.analyseResourceLeaks) {
FakedTrackingVariable.cleanUpUnassigned(this.scope, stat, flowInfo);
}
}
} else {
// method with empty body should not be flagged as static.
this.bits &= ~ASTNode.CanBeStatic;
}
// check for missing returning path
TypeBinding returnTypeBinding = this.binding.returnType;
if ((returnTypeBinding == TypeBinding.VOID) || isAbstract()) {
if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) {
this.bits |= ASTNode.NeedFreeReturn;
}
} else {
if (flowInfo != FlowInfo.DEAD_END) {
this.scope.problemReporter().shouldReturn(returnTypeBinding, this);
}
}
// check unreachable catch blocks
methodContext.complainIfUnusedExceptionHandlers(this);
// check unused parameters
this.scope.checkUnusedParameters(this.binding);
// check if the method could have been static
if (!this.binding.isStatic() && (this.bits & ASTNode.CanBeStatic) != 0 && !this.isDefaultMethod()) {
if (!this.binding.isOverriding() && !this.binding.isImplementing()) {
if (this.binding.isPrivate() || this.binding.isFinal() || this.binding.declaringClass.isFinal()) {
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;
}
}
use of org.eclipse.jdt.internal.compiler.flow.ExceptionHandlingFlowContext in project bazel-jdt-java-toolchain by salesforce.
the class LambdaExpression method analyseCode.
@Override
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, final FlowInfo flowInfo) {
if (this.ignoreFurtherInvestigation)
return flowInfo;
// what happens in vegas, stays in vegas ...
FlowInfo lambdaInfo = flowInfo.copy();
ExceptionHandlingFlowContext methodContext = new ExceptionHandlingFlowContext(flowContext, this, this.binding.thrownExceptions, flowContext.getInitializationContext(), this.scope, FlowInfo.DEAD_END);
// nullity and mark as assigned
MethodBinding methodWithParameterDeclaration = argumentsTypeElided() ? this.descriptor : this.binding;
AbstractMethodDeclaration.analyseArguments(currentScope.environment(), lambdaInfo, this.arguments, methodWithParameterDeclaration);
if (this.arguments != null) {
for (int i = 0, count = this.arguments.length; i < count; i++) {
this.bits |= (this.arguments[i].bits & ASTNode.HasTypeAnnotations);
}
}
lambdaInfo = this.body.analyseCode(this.scope, methodContext, lambdaInfo);
// check for missing returning path for block body's ...
if (this.body instanceof Block) {
TypeBinding returnTypeBinding = expectedResultType();
if ((returnTypeBinding == TypeBinding.VOID)) {
if ((lambdaInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0 || ((Block) this.body).statements == null) {
this.bits |= ASTNode.NeedFreeReturn;
}
} else {
if (lambdaInfo != FlowInfo.DEAD_END) {
this.scope.problemReporter().shouldReturn(returnTypeBinding, this);
}
}
} else {
// Expression
if (currentScope.compilerOptions().isAnnotationBasedNullAnalysisEnabled && lambdaInfo.reachMode() == FlowInfo.REACHABLE) {
Expression expression = (Expression) this.body;
checkAgainstNullAnnotation(flowContext, expression, flowInfo, expression.nullStatus(lambdaInfo, flowContext));
}
}
return flowInfo;
}
Aggregations