use of org.checkerframework.dataflow.cfg.node.ImplicitThisLiteralNode in project checker-framework by typetools.
the class FlowExpressionParseUtil method getReceiverField.
private static Receiver getReceiverField(String s, FlowExpressionContext context, boolean originalReceiver, VariableElement fieldElem) throws FlowExpressionParseException {
TypeMirror receiverType = context.receiver.getType();
TypeMirror fieldType = ElementUtils.getType(fieldElem);
if (ElementUtils.isStatic(fieldElem)) {
Element classElem = fieldElem.getEnclosingElement();
Receiver staticClassReceiver = new ClassName(ElementUtils.getType(classElem));
return new FieldAccess(staticClassReceiver, fieldType, fieldElem);
}
Receiver locationOfField;
if (originalReceiver) {
locationOfField = context.receiver;
} else {
locationOfField = FlowExpressions.internalReprOf(context.checkerContext.getAnnotationProvider(), new ImplicitThisLiteralNode(receiverType));
}
if (locationOfField instanceof ClassName) {
throw constructParserException(s, "a non-static field cannot have a class name as a receiver.");
}
return new FieldAccess(locationOfField, fieldType, fieldElem);
}
use of org.checkerframework.dataflow.cfg.node.ImplicitThisLiteralNode in project checker-framework by typetools.
the class WholeProgramInferenceScenes method getEnclosingClassSymbol.
/**
* Returns the ClassSymbol of the class encapsulating the node n passed as parameter.
*
* <p>If the receiver of field is an instance of "this", the implementation obtains the
* ClassSymbol by using classTree. Otherwise, the ClassSymbol is from the field's receiver.
*/
// TODO: These methods below could be moved somewhere else.
private ClassSymbol getEnclosingClassSymbol(ClassTree classTree, Node field) {
Node receiverNode = null;
if (field instanceof FieldAccessNode) {
receiverNode = ((FieldAccessNode) field).getReceiver();
} else if (field instanceof LocalVariableNode) {
receiverNode = ((LocalVariableNode) field).getReceiver();
} else {
ErrorReporter.errorAbort("Unexpected type: " + field.getClass());
}
if ((receiverNode == null || receiverNode instanceof ImplicitThisLiteralNode) && classTree != null) {
return (ClassSymbol) TreeUtils.elementFromTree(classTree);
}
TypeMirror type = receiverNode.getType();
if (type instanceof ClassType) {
TypeSymbol tsym = ((ClassType) type).asElement();
return tsym.enclClass();
}
return getEnclosingClassSymbol(receiverNode.getTree());
}
Aggregations