blob: 310d80efc34f30c65d1f9354e18b15c0762621e6 [file] [log] [blame]
/**
* This file was copied and re-packaged automatically by
* org.eclipse.qvtd.doc.miniocl.build.MiniOCLBuildEverything
* from
* ..\..\plugins\org.eclipse.qvtd.runtime\src\org\eclipse\qvtd\runtime\internal\cs2as\AbstractCS2ASTransformer.java
*
* Do not edit this file.
*/
/*******************************************************************************
* Copyright (c) 2015, 2019 Willink Transformations and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* E.D.Willink - initial API and implementation
*******************************************************************************/
package org.eclipse.qvtd.doc.minioclcs.xtext.tx;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.ocl.pivot.ids.ClassId;
import org.eclipse.ocl.pivot.ids.PropertyId;
public abstract class AbstractCS2ASTransformer extends AbstractTransformer
implements CS2ASTransformer
{
private final List<CS2ASDiagnostic> txErrors = new ArrayList<CS2ASDiagnostic>();
protected AbstractCS2ASTransformer(@NonNull TransformationExecutor executor, @NonNull String @NonNull [] modelNames,
@NonNull PropertyId @Nullable [] propertyIndex2propertyId, @NonNull ClassId @NonNull [] classIndex2classId, int @Nullable [] @NonNull [] classIndex2allClassIndexes) {
super(executor, modelNames, propertyIndex2propertyId, classIndex2classId, classIndex2allClassIndexes);
}
protected @NonNull RuntimeException throwNull(@NonNull EObject csObject, @NonNull String message) {
throw new CS2ASException(csObject, message);
}
protected void handleLookupError(@Nullable String mentor, String lookupHint) {
throw new RuntimeException(mentor + lookupHint);
}
protected void handleLookupError(EObject sourceObject, EObject lookupHint) {
handleError(sourceObject, "''" + lookupHint.toString() +"'' not found");
}
protected void handleLookupError(@Nullable Object aPathElementCS_0,
@Nullable String name_1) {
throw new RuntimeException(aPathElementCS_0 + name_1);
}
protected void handleLookupError(List<? extends EObject> sourceObjects, EObject lookupHint) {
int hintPos = sourceObjects.indexOf(lookupHint);
switch (hintPos) {
case -1:
case 0:
hintPos = 0; // For safety, the default will be the first one
break;
default:
// We assume the element from which we report is the previous one of the lookupHint
hintPos = hintPos -1;
}
handleError(sourceObjects.get(hintPos), "''" + lookupHint.toString() +"'' not found");
}
protected void handleError(EObject sourceObject, String errorMessage) {
txErrors.add(new CS2ASDiagnostic(sourceObject, errorMessage));
}
@Override
public List<CS2ASDiagnostic> getErrors() {
return txErrors;
}
}