ErrorModelCrossReferenceSerializer.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.xtext.aadl2.errormodel.serializer;
import com.google.common.base.Objects;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.CrossReference;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.GrammarUtil;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic;
import org.eclipse.xtext.serializer.tokens.CrossReferenceSerializer;
import org.osate.aadl2.AadlPackage;
import org.osate.aadl2.NamedElement;
import org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelPackage;
import org.osate.xtext.aadl2.errormodel.errorModel.ErrorTypes;
@SuppressWarnings("all")
public class ErrorModelCrossReferenceSerializer extends CrossReferenceSerializer {
public static final String PREFIX = "emv2$";
@Override
public String serializeCrossRef(final EObject semanticObject, final CrossReference crossref, final EObject target, final INode node, final ISerializationDiagnostic.Acceptor errors) {
String _xblockexpression = null;
{
final String crossRefString = super.serializeCrossRef(semanticObject, crossref, target, node, errors);
String _xifexpression = null;
boolean _startsWith = crossRefString.startsWith(ErrorModelCrossReferenceSerializer.PREFIX);
if (_startsWith) {
_xifexpression = crossRefString.substring(ErrorModelCrossReferenceSerializer.PREFIX.length());
} else {
_xifexpression = crossRefString;
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
@Override
protected String getCrossReferenceNameFromScope(final EObject semanticObject, final CrossReference crossref, final EObject target, final IScope scope, final ISerializationDiagnostic.Acceptor errors) {
String _switchResult = null;
EReference _reference = GrammarUtil.getReference(crossref);
boolean _matched = false;
if (Objects.equal(_reference, ErrorModelPackage.Literals.TYPE_TOKEN__TYPE)) {
_matched=true;
}
if (!_matched) {
if (Objects.equal(_reference, ErrorModelPackage.Literals.ERROR_TYPE__SUPER_TYPE)) {
_matched=true;
}
}
if (!_matched) {
if (Objects.equal(_reference, ErrorModelPackage.Literals.ERROR_TYPE__ALIASED_TYPE)) {
_matched=true;
}
}
if (!_matched) {
if (Objects.equal(_reference, ErrorModelPackage.Literals.TYPE_SET__ALIASED_TYPE)) {
_matched=true;
}
}
if (_matched) {
String _xblockexpression = null;
{
final String simpleName = ((ErrorTypes) target).getName();
final IEObjectDescription fromScope = scope.getSingleElement(QualifiedName.create(simpleName));
String _xifexpression = null;
if (((fromScope == null) || (!Objects.equal(EcoreUtil2.<AadlPackage>getContainerOfType(fromScope.getEObjectOrProxy(), AadlPackage.class),
EcoreUtil2.<AadlPackage>getContainerOfType(target, AadlPackage.class))))) {
String _name = EcoreUtil2.<AadlPackage>getContainerOfType(target, AadlPackage.class).getName();
String _plus = (_name + "::");
_xifexpression = (_plus + simpleName);
} else {
_xifexpression = simpleName;
}
_xblockexpression = _xifexpression;
}
_switchResult = _xblockexpression;
}
if (!_matched) {
if (Objects.equal(_reference, ErrorModelPackage.Literals.ERROR_MODEL_LIBRARY__EXTENDS)) {
_matched=true;
String _xblockexpression_1 = null;
{
final AadlPackage package_ = EcoreUtil2.<AadlPackage>getContainerOfType(target, AadlPackage.class);
String _name = null;
if (package_!=null) {
_name=package_.getName();
}
_xblockexpression_1 = _name;
}
_switchResult = _xblockexpression_1;
}
}
if (!_matched) {
if (Objects.equal(_reference, ErrorModelPackage.Literals.FEATUREOR_PP_REFERENCE__FEATUREOR_PP)) {
_matched=true;
}
if (!_matched) {
if (Objects.equal(_reference, ErrorModelPackage.Literals.QUALIFIED_PROPAGATION_POINT__PROPAGATION_POINT)) {
_matched=true;
}
}
if (!_matched) {
if (Objects.equal(_reference, ErrorModelPackage.Literals.SUBCOMPONENT_ELEMENT__SUBCOMPONENT)) {
_matched=true;
}
}
if (_matched) {
String _name = null;
if (((NamedElement) target)!=null) {
_name=((NamedElement) target).getName();
}
_switchResult = _name;
}
}
if (!_matched) {
_switchResult = super.getCrossReferenceNameFromScope(semanticObject, crossref, target, scope, errors);
}
return _switchResult;
}
}