/** Replies if the given object is locally assigned. * * <p>An object is locally assigned when it is the left operand of an assignment operation. * * @param target the object to test. * @param containerToFindUsage the container in which the usages should be find. * @return {@code true} if the given object is assigned. * @since 0.7 */ protected boolean isLocallyAssigned(EObject target, EObject containerToFindUsage) { if (this.readAndWriteTracking.isAssigned(target)) { return true; } final Collection<Setting> usages = XbaseUsageCrossReferencer.find(target, containerToFindUsage); // field are assigned when they are not used as the left operand of an assignment operator. for (final Setting usage : usages) { final EObject object = usage.getEObject(); if (object instanceof XAssignment) { final XAssignment assignment = (XAssignment) object; if (assignment.getFeature() == target) { // Mark the field as assigned in order to be faster during the next assignment test. this.readAndWriteTracking.markAssignmentAccess(target); return true; } } } return false; }
/** Mark the given object as an assigned object after its initialization. * * <p>The given object has its value changed by a assignment operation. * * @param object the written object. * @return {@code true} if the write flag has changed. */ public boolean markAssignmentAccess(EObject object) { assert object != null; if (!isAssigned(object)) { return object.eAdapters().add(ASSIGNMENT_MARKER); } return false; }
@Override protected boolean isInitialized(JvmField input) { if (super.isInitialized(input)) { return true; } // Check initialization into a static constructor. final XtendField sarlField = (XtendField) this.associations.getPrimarySourceElement(input); if (sarlField == null) { return false; } final XtendTypeDeclaration declaringType = sarlField.getDeclaringType(); if (declaringType == null) { return false; } for (final XtendConstructor staticConstructor : Iterables.filter(Iterables.filter( declaringType.getMembers(), XtendConstructor.class), it -> it.isStatic())) { if (staticConstructor.getExpression() != null) { for (final XAssignment assign : EcoreUtil2.getAllContentsOfType(staticConstructor.getExpression(), XAssignment.class)) { if (assign.isStatic() && Strings.equal(input.getIdentifier(), assign.getFeature().getIdentifier())) { // Mark the field as initialized in order to be faster during the next initialization test. this.readAndWriteTracking.markInitialized(input, null); return true; } } } } return false; }