org.checkerframework.common.initializedfields.InitializedFieldsTransfer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of checker Show documentation
Show all versions of checker Show documentation
The Checker Framework enhances Java's type system to
make it more powerful and useful. This lets software developers
detect and prevent errors in their Java programs.
The Checker Framework includes compiler plug-ins ("checkers")
that find bugs or verify their absence. It also permits you to
write your own compiler plug-ins.
package org.checkerframework.common.initializedfields;
import org.checkerframework.common.accumulation.AccumulationAnalysis;
import org.checkerframework.common.accumulation.AccumulationStore;
import org.checkerframework.common.accumulation.AccumulationTransfer;
import org.checkerframework.common.accumulation.AccumulationValue;
import org.checkerframework.dataflow.analysis.TransferInput;
import org.checkerframework.dataflow.analysis.TransferResult;
import org.checkerframework.dataflow.cfg.node.AssignmentNode;
import org.checkerframework.dataflow.cfg.node.FieldAccessNode;
import org.checkerframework.dataflow.cfg.node.Node;
/** Accumulates the names of fields that are initialized. */
public class InitializedFieldsTransfer extends AccumulationTransfer {
/**
* Create an InitializedFieldsTransfer.
*
* @param analysis the analysis
*/
public InitializedFieldsTransfer(AccumulationAnalysis analysis) {
super(analysis);
}
@Override
public TransferResult visitAssignment(
AssignmentNode node, TransferInput input) {
TransferResult result =
super.visitAssignment(node, input);
Node lhs = node.getTarget();
if (lhs instanceof FieldAccessNode) {
FieldAccessNode fieldAccess = (FieldAccessNode) lhs;
accumulate(fieldAccess.getReceiver(), result, fieldAccess.getFieldName());
}
return result;
}
}