use of org.eclipse.jdt.internal.compiler.flow.FlowInfo in project bazel-jdt-java-toolchain by salesforce.
the class CastExpression method analyseCode.
@Override
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
FlowInfo result = this.expression.analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
this.expression.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
// account for pot. CCE:
flowContext.recordAbruptExit();
return result;
}
use of org.eclipse.jdt.internal.compiler.flow.FlowInfo in project bazel-jdt-java-toolchain by salesforce.
the class FakedTrackingVariable method markPassedToOutside.
/**
* Mark that this resource is passed to some outside code
* (as argument to a method/ctor call or as a return value from the current method),
* and thus should be considered as potentially closed.
* @param owned should the resource be considered owned by some outside?
*/
public static FlowInfo markPassedToOutside(BlockScope scope, Expression expression, FlowInfo flowInfo, FlowContext flowContext, boolean owned) {
FakedTrackingVariable trackVar = getCloseTrackingVariable(expression, flowInfo, flowContext);
if (trackVar != null) {
// insert info that the tracked resource *may* be closed (by the target method, i.e.)
FlowInfo infoResourceIsClosed = owned ? flowInfo : flowInfo.copy();
int flag = owned ? OWNED_BY_OUTSIDE : SHARED_WITH_OUTSIDE;
do {
trackVar.globalClosingState |= flag;
if (scope.methodScope() != trackVar.methodScope)
trackVar.globalClosingState |= CLOSED_IN_NESTED_METHOD;
infoResourceIsClosed.markAsDefinitelyNonNull(trackVar.binding);
} while ((trackVar = trackVar.innerTracker) != null);
if (owned) {
// don't let downstream signal any problems on this flow
return infoResourceIsClosed;
} else {
// only report potential problems on this flow
return FlowInfo.conditional(flowInfo, infoResourceIsClosed).unconditionalCopy();
}
}
return flowInfo;
}
use of org.eclipse.jdt.internal.compiler.flow.FlowInfo in project bazel-jdt-java-toolchain by salesforce.
the class FieldReference method analyseCode.
@Override
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, boolean valueRequired) {
boolean nonStatic = !this.binding.isStatic();
this.receiver.analyseCode(currentScope, flowContext, flowInfo, nonStatic);
if (nonStatic) {
this.receiver.checkNPE(currentScope, flowContext, flowInfo, 1);
}
if (valueRequired || currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) {
manageSyntheticAccessIfNecessary(currentScope, flowInfo, true);
}
if (currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_7) {
FieldBinding fieldBinding = this.binding;
if (this.receiver.isThis() && fieldBinding.isBlankFinal() && currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) {
FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(fieldBinding.declaringClass.original(), flowInfo);
if (!fieldInits.isDefinitelyAssigned(fieldBinding)) {
currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
}
}
}
return flowInfo;
}
use of org.eclipse.jdt.internal.compiler.flow.FlowInfo in project bazel-jdt-java-toolchain by salesforce.
the class QualifiedNameReference method analyseAssignment.
@Override
public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, Assignment assignment, boolean isCompound) {
// determine the rank until which we now we do not need any actual value for the field access
int otherBindingsCount = this.otherBindings == null ? 0 : this.otherBindings.length;
boolean needValue = otherBindingsCount == 0 || !this.otherBindings[0].isStatic();
boolean complyTo14 = currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4;
FieldBinding lastFieldBinding = null;
switch(this.bits & ASTNode.RestrictiveFlagMASK) {
case // reading a field
Binding.FIELD:
lastFieldBinding = (FieldBinding) this.binding;
if (needValue || complyTo14) {
manageSyntheticAccessIfNecessary(currentScope, lastFieldBinding, 0, flowInfo);
}
// check if final blank field
if (lastFieldBinding.isBlankFinal() && // the last field binding is only assigned
this.otherBindings != null && currentScope.needBlankFinalFieldInitializationCheck(lastFieldBinding)) {
FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(lastFieldBinding.declaringClass.original(), flowInfo);
if (!fieldInits.isDefinitelyAssigned(lastFieldBinding)) {
currentScope.problemReporter().uninitializedBlankFinalField(lastFieldBinding, this);
}
}
if (needValue) {
checkInternalNPE(currentScope, flowContext, flowInfo, true);
}
break;
case Binding.LOCAL:
// first binding is a local variable
LocalVariableBinding localBinding;
if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) this.binding)) {
currentScope.problemReporter().uninitializedLocalVariable(localBinding, this, currentScope);
}
if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) {
localBinding.useFlag = LocalVariableBinding.USED;
} else if (localBinding.useFlag == LocalVariableBinding.UNUSED) {
localBinding.useFlag = LocalVariableBinding.FAKE_USED;
}
if (needValue) {
checkInternalNPE(currentScope, flowContext, flowInfo, true);
}
}
if (needValue) {
manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo);
// only for first binding
}
// all intermediate field accesses are read accesses
if (this.otherBindings != null) {
for (int i = 0; i < otherBindingsCount - 1; i++) {
lastFieldBinding = this.otherBindings[i];
needValue = !this.otherBindings[i + 1].isStatic();
if (needValue || complyTo14) {
manageSyntheticAccessIfNecessary(currentScope, lastFieldBinding, i + 1, flowInfo);
}
}
lastFieldBinding = this.otherBindings[otherBindingsCount - 1];
}
if (isCompound) {
if (otherBindingsCount == 0 && lastFieldBinding.isBlankFinal() && currentScope.needBlankFinalFieldInitializationCheck(lastFieldBinding)) {
FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(lastFieldBinding.declaringClass, flowInfo);
if (!fieldInits.isDefinitelyAssigned(lastFieldBinding)) {
currentScope.problemReporter().uninitializedBlankFinalField(lastFieldBinding, this);
}
}
manageSyntheticAccessIfNecessary(currentScope, lastFieldBinding, otherBindingsCount, flowInfo);
}
if (assignment.expression != null) {
flowInfo = assignment.expression.analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
}
// the last field access is a write access
if (lastFieldBinding.isFinal()) {
// in a context where it can be assigned?
if (otherBindingsCount == 0 && this.indexOfFirstFieldBinding == 1 && lastFieldBinding.isBlankFinal() && !isCompound && currentScope.allowBlankFinalFieldAssignment(lastFieldBinding)) {
if (flowInfo.isPotentiallyAssigned(lastFieldBinding)) {
currentScope.problemReporter().duplicateInitializationOfBlankFinalField(lastFieldBinding, this);
} else {
flowContext.recordSettingFinal(lastFieldBinding, this, flowInfo);
}
flowInfo.markAsDefinitelyAssigned(lastFieldBinding);
} else {
currentScope.problemReporter().cannotAssignToFinalField(lastFieldBinding, this);
if (otherBindingsCount == 0 && currentScope.allowBlankFinalFieldAssignment(lastFieldBinding)) {
// pretend it got assigned
flowInfo.markAsDefinitelyAssigned(lastFieldBinding);
}
}
}
// note: not covering def.assign for @NonNull: QNR cannot provably refer to a variable of the current object
manageSyntheticAccessIfNecessary(currentScope, lastFieldBinding, -1, /*write-access*/
flowInfo);
return flowInfo;
}
use of org.eclipse.jdt.internal.compiler.flow.FlowInfo in project bazel-jdt-java-toolchain by salesforce.
the class QualifiedNameReference method analyseCode.
@Override
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, boolean valueRequired) {
// determine the rank until which we now we do not need any actual value for the field access
int otherBindingsCount = this.otherBindings == null ? 0 : this.otherBindings.length;
boolean needValue = otherBindingsCount == 0 ? valueRequired : !this.otherBindings[0].isStatic();
boolean complyTo14 = currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4;
switch(this.bits & ASTNode.RestrictiveFlagMASK) {
case // reading a field
Binding.FIELD:
if (needValue || complyTo14) {
manageSyntheticAccessIfNecessary(currentScope, (FieldBinding) this.binding, 0, flowInfo);
}
FieldBinding fieldBinding = (FieldBinding) this.binding;
if (this.indexOfFirstFieldBinding == 1) {
// check if reading a final blank field
if (fieldBinding.isBlankFinal() && currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) {
FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(fieldBinding.declaringClass.original(), flowInfo);
if (!fieldInits.isDefinitelyAssigned(fieldBinding)) {
currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
}
}
}
break;
case // reading a local variable
Binding.LOCAL:
LocalVariableBinding localBinding;
if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) this.binding)) {
currentScope.problemReporter().uninitializedLocalVariable(localBinding, this, currentScope);
}
if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) {
localBinding.useFlag = LocalVariableBinding.USED;
} else if (localBinding.useFlag == LocalVariableBinding.UNUSED) {
localBinding.useFlag = LocalVariableBinding.FAKE_USED;
}
}
if (needValue) {
checkInternalNPE(currentScope, flowContext, flowInfo, true);
}
if (needValue) {
manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo);
// only for first binding (if value needed only)
}
if (this.otherBindings != null) {
for (int i = 0; i < otherBindingsCount; i++) {
needValue = i < otherBindingsCount - 1 ? !this.otherBindings[i + 1].isStatic() : valueRequired;
if (needValue || complyTo14) {
manageSyntheticAccessIfNecessary(currentScope, this.otherBindings[i], i + 1, flowInfo);
}
}
}
return flowInfo;
}
Aggregations