VerifyScopeProvider.java
/**
* Copyright (c) 2004-2025 Carnegie Mellon University and others. (see Contributors file).
* All Rights Reserved.
*
* NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY
* KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE
* OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT
* MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
* SPDX-License-Identifier: EPL-2.0
*
* Created, in part, with funding and support from the United States Government. (see Acknowledgments file).
*
* This program includes and/or can make use of certain third party source code, object code, documentation and other
* files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system
* configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and
* conditions contained in any such Third Party Software or separate license file distributed with such Third Party
* Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party benefici-
* aries to this license with respect to the terms applicable to their Third Party Software. Third Party Software li-
* censes only apply to the Third Party Software and not any other portion of this program or this program as a whole.
*/
package org.osate.verify.scoping;
import java.util.Collections;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.EObjectDescription;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.Scopes;
import org.eclipse.xtext.scoping.impl.SimpleScope;
import org.eclipse.xtext.util.SimpleAttributeResolver;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.osate.aadl2.ComponentClassifier;
import org.osate.aadl2.NamedElement;
import org.osate.alisa.common.common.AVariableReference;
import org.osate.alisa.common.scoping.CommonScopeProvider;
import org.osate.reqspec.reqSpec.Requirement;
import org.osate.reqspec.reqSpec.RequirementSet;
import org.osate.reqspec.reqSpec.SystemRequirementSet;
import org.osate.reqspec.util.ReqSpecUtilExtension;
import org.osate.verify.internal.util.VerifyUtilExtension;
import org.osate.verify.verify.Claim;
import org.osate.verify.verify.FormalParameter;
import org.osate.verify.verify.VerificationActivity;
import org.osate.verify.verify.VerificationMethod;
/**
* This class contains custom scoping description.
*
* see : http://www.eclipse.org/Xtext/documentation.html#scoping
* on how and when to use it
*/
@SuppressWarnings("all")
public class VerifyScopeProvider extends CommonScopeProvider {
public IScope scope_ValDeclaration(final VerificationActivity context, final EReference reference) {
final Claim claim = VerifyUtilExtension.getContainingClaim(context);
Requirement req = claim.getRequirement();
final IScope result = ReqSpecUtilExtension.scopeForGlobalVal(req, IScope.NULLSCOPE);
return ReqSpecUtilExtension.scopeForVal(req, result);
}
public IScope scope_AVariableReference_variable(final AVariableReference context, final EReference reference) {
final Claim claim = VerifyUtilExtension.getContainingClaim(context);
Requirement req = claim.getRequirement();
final IScope result1 = ReqSpecUtilExtension.scopeForGlobalVal(req, IScope.NULLSCOPE);
final IScope result2 = ReqSpecUtilExtension.scopeForCompute(req, result1);
return ReqSpecUtilExtension.scopeForVal(req, result2);
}
public IScope scope_ComputeDeclaration(final VerificationActivity context, final EReference reference) {
final Claim claim = VerifyUtilExtension.getContainingClaim(context);
Requirement req = claim.getRequirement();
final IScope result = IScope.NULLSCOPE;
return ReqSpecUtilExtension.scopeForCompute(req, result);
}
public IScope scope_Claim_requirement(final Claim context, final EReference reference) {
IScope result = this.delegateGetScope(context, reference);
final RequirementSet forSystemRequirements = VerifyUtilExtension.containingVerificationPlan(context).getRequirementSet();
boolean _isEmpty = forSystemRequirements.getRequirements().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
Iterable<IEObjectDescription> _scopedElementsFor = Scopes.<EObject>scopedElementsFor(forSystemRequirements.getRequirements(),
QualifiedName.<EObject>wrapper(SimpleAttributeResolver.NAME_RESOLVER));
SimpleScope _simpleScope = new SimpleScope(result, _scopedElementsFor, false);
result = _simpleScope;
}
return result;
}
public SimpleScope scope_VerificationActivity(final EObject context, final EReference reference) {
SimpleScope _xblockexpression = null;
{
final EList<VerificationActivity> vas = VerifyUtilExtension.getContainingClaim(context).getActivities();
Iterable<IEObjectDescription> _scopedElementsFor = Scopes.<EObject>scopedElementsFor(vas,
QualifiedName.<EObject>wrapper(SimpleAttributeResolver.NAME_RESOLVER));
_xblockexpression = new SimpleScope(IScope.NULLSCOPE, _scopedElementsFor, false);
}
return _xblockexpression;
}
public SimpleScope scope_FormalParameter(final EObject context, final EReference reference) {
SimpleScope _xblockexpression = null;
{
VerificationMethod _containingVerificationMethod = VerifyUtilExtension.getContainingVerificationMethod(context);
EList<FormalParameter> _formals = null;
if (_containingVerificationMethod!=null) {
_formals=_containingVerificationMethod.getFormals();
}
final EList<FormalParameter> formalparams = _formals;
Iterable<IEObjectDescription> _scopedElementsFor = Scopes.<EObject>scopedElementsFor(formalparams,
QualifiedName.<EObject>wrapper(SimpleAttributeResolver.NAME_RESOLVER));
_xblockexpression = new SimpleScope(IScope.NULLSCOPE, _scopedElementsFor, false);
}
return _xblockexpression;
}
@Override
public IScope scope_AModelReference_modelElement(final EObject context, final EReference reference) {
SimpleScope _xblockexpression = null;
{
EObject _eContainer = context.eContainer();
final Claim claim = ((Claim) _eContainer);
final Requirement contractualElement = claim.getRequirement();
NamedElement _elvis = null;
NamedElement _elvis_1 = null;
NamedElement _targetElement = null;
if (contractualElement!=null) {
_targetElement=contractualElement.getTargetElement();
}
if (_targetElement != null) {
_elvis_1 = _targetElement;
} else {
ComponentClassifier _target = null;
if (contractualElement!=null) {
_target=contractualElement.getTarget();
}
_elvis_1 = _target;
}
if (_elvis_1 != null) {
_elvis = _elvis_1;
} else {
ComponentClassifier _target_1 = EcoreUtil2.<SystemRequirementSet>getContainerOfType(contractualElement, SystemRequirementSet.class).getTarget();
_elvis = _target_1;
}
final NamedElement target = _elvis;
IEObjectDescription _create = EObjectDescription.create("this", target);
_xblockexpression = new SimpleScope(Collections.<IEObjectDescription>unmodifiableList(CollectionLiterals.<IEObjectDescription>newArrayList(_create)));
}
return _xblockexpression;
}
}