[502235] Diagnose all CS creation errors
diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiCG2JavaVisitor.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiCG2JavaVisitor.java
index 15f8ce6..f06bfe1 100644
--- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiCG2JavaVisitor.java
+++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiCG2JavaVisitor.java
@@ -853,19 +853,6 @@
}
}
- private EObject getContainer(EObject eObject) {
- EObject eContainer = eObject.eContainer();
- if (eContainer != null) {
- return eContainer;
- }
- for (Adapter eAdapter : eObject.eAdapters()) {
- if (eAdapter instanceof QVTiAS2CGVisitor.InlinedBodyAdapter) {
- return ((QVTiAS2CGVisitor.InlinedBodyAdapter)eAdapter).getOperationCallExp();
- }
- }
- return null;
- }
-
protected void doGot(@NonNull CGNavigationCallExp cgPropertyCallExp, @NonNull CGValuedElement source, @NonNull EStructuralFeature eStructuralFeature) {
if (useGot) {
EPackage ePackage = ClassUtil.nonNullModel(eStructuralFeature.getEContainingClass().getEPackage());
@@ -1160,6 +1147,19 @@
return allImports;
}
+ private EObject getContainer(EObject eObject) {
+ EObject eContainer = eObject.eContainer();
+ if (eContainer != null) {
+ return eContainer;
+ }
+ for (Adapter eAdapter : eObject.eAdapters()) {
+ if (eAdapter instanceof QVTiAS2CGVisitor.InlinedBodyAdapter) {
+ return ((QVTiAS2CGVisitor.InlinedBodyAdapter)eAdapter).getOperationCallExp();
+ }
+ }
+ return null;
+ }
+
@Override
protected @Nullable EStructuralFeature getESObject(@NonNull Property asProperty) {
EObject esObject = asProperty.getESObject();
@@ -1171,7 +1171,7 @@
return null;
}
if (!oppositeProperty.isIsComposite()) {
- PivotMetamodelManager metamodelManager = analyzer.getCodeGenerator().getEnvironmentFactory().getMetamodelManager();
+ PivotMetamodelManager metamodelManager = environmentFactory.getMetamodelManager();
LibraryProperty libraryProperty = metamodelManager.getImplementation(null, null, asProperty);
if (!(libraryProperty instanceof OclElementOclContainerProperty)) {
return null;
@@ -2105,7 +2105,7 @@
List<CGOperation> cgOperations = cgTransformation.getOperations();
doMappingConstructorConstants(cgMappings);
doFunctionConstructorConstants(ClassUtil.nullFree(cgOperations));
- // js.append("\n");
+ js.append("\n");
doConstructor(cgTransformation, oppositeIndex2propertyIdName, allInstancesNames);
js.append("\n");
if (isIncremental) {
diff --git a/plugins/org.eclipse.qvtd.cs2as.compiler/src/org/eclipse/qvtd/cs2as/compiler/OCL2JavaTxCompiler.java b/plugins/org.eclipse.qvtd.cs2as.compiler/src/org/eclipse/qvtd/cs2as/compiler/OCL2JavaTxCompiler.java
index 0b78d28..303fd7f 100644
--- a/plugins/org.eclipse.qvtd.cs2as.compiler/src/org/eclipse/qvtd/cs2as/compiler/OCL2JavaTxCompiler.java
+++ b/plugins/org.eclipse.qvtd.cs2as.compiler/src/org/eclipse/qvtd/cs2as/compiler/OCL2JavaTxCompiler.java
@@ -19,12 +19,12 @@
public interface OCL2JavaTxCompiler<P extends OCL2JavaTxCompilerParams> {
// FIXME fix exception handling
-
+
public Class<? extends Transformer> compileTransformation(@Nullable ResourceSet rSet,
@NonNull CS2ASJavaCompilerParameters params, @NonNull URI oclDocURI,
- URI... extendedOCLDocURIs) throws Exception;
-
+ @NonNull URI... extendedOCLDocURIs) throws Exception;
+
public Class<? extends Transformer> compileTransformation(@Nullable ResourceSet rSet,
@NonNull CS2ASJavaCompilerParameters params, @NonNull String tracePropertyName, @NonNull URI oclDocURI,
- URI... extendedOCLDocURIs) throws Exception;
+ @NonNull URI... extendedOCLDocURIs) throws Exception;
}
diff --git a/plugins/org.eclipse.qvtd.cs2as.compiler/src/org/eclipse/qvtd/cs2as/compiler/OCL2QVTiCGTxCompiler.java b/plugins/org.eclipse.qvtd.cs2as.compiler/src/org/eclipse/qvtd/cs2as/compiler/OCL2QVTiCGTxCompiler.java
index 395c8d0..a2c4041 100644
--- a/plugins/org.eclipse.qvtd.cs2as.compiler/src/org/eclipse/qvtd/cs2as/compiler/OCL2QVTiCGTxCompiler.java
+++ b/plugins/org.eclipse.qvtd.cs2as.compiler/src/org/eclipse/qvtd/cs2as/compiler/OCL2QVTiCGTxCompiler.java
@@ -50,7 +50,7 @@
}
@Override
- public Class<? extends Transformer> compileTransformation(@Nullable ResourceSet rSet, @NonNull CS2ASJavaCompilerParameters params, @NonNull String tracePropertyName, @NonNull URI oclDocURI, URI... extendedOCLDocURIs)
+ public Class<? extends Transformer> compileTransformation(@Nullable ResourceSet rSet, @NonNull CS2ASJavaCompilerParameters params, @NonNull String tracePropertyName, @NonNull URI oclDocURI, @NonNull URI... extendedOCLDocURIs)
throws Exception {
QVTimperative qvt = QVTimperative.newInstance(BasicProjectManager.CLASS_PATH, rSet);
@@ -68,7 +68,7 @@
return new CS2ASJavaCompilerImpl();
}
- protected Transformation executeOCL2QVTi_CompilerChain(QVTimperative qvt, String tracePropName, URI oclDocURI, URI... extendedOCLDocURIs) throws Exception {
+ protected @NonNull Transformation executeOCL2QVTi_CompilerChain(@NonNull QVTimperative qvt, String tracePropName, @NonNull URI oclDocURI, @NonNull URI... extendedOCLDocURIs) throws Exception {
Map<@NonNull String, @Nullable Map<@NonNull Key<Object>, @Nullable Object>> options = new HashMap<@NonNull String, @Nullable Map<@NonNull Key<Object>, @Nullable Object>>();
// OCL2QVTp options
diff --git a/plugins/org.eclipse.qvtd.cs2as.compiler/src/org/eclipse/qvtd/cs2as/compiler/internal/OCL2QVTiCompilerChain.java b/plugins/org.eclipse.qvtd.cs2as.compiler/src/org/eclipse/qvtd/cs2as/compiler/internal/OCL2QVTiCompilerChain.java
index c8de185..7efe60e 100644
--- a/plugins/org.eclipse.qvtd.cs2as.compiler/src/org/eclipse/qvtd/cs2as/compiler/internal/OCL2QVTiCompilerChain.java
+++ b/plugins/org.eclipse.qvtd.cs2as.compiler/src/org/eclipse/qvtd/cs2as/compiler/internal/OCL2QVTiCompilerChain.java
@@ -18,14 +18,18 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.ocl.pivot.Element;
+import org.eclipse.ocl.pivot.resource.ASResource;
+import org.eclipse.ocl.pivot.resource.CSResource;
import org.eclipse.ocl.pivot.utilities.ClassUtil;
import org.eclipse.ocl.pivot.utilities.PivotUtil;
import org.eclipse.qvtd.compiler.AbstractCompilerChain;
import org.eclipse.qvtd.compiler.AbstractCompilerStep;
import org.eclipse.qvtd.compiler.CompilerChain;
+import org.eclipse.qvtd.compiler.CompilerChainException;
import org.eclipse.qvtd.pivot.qvtimperative.ImperativeTransformation;
import org.eclipse.qvtd.pivot.qvtimperative.utilities.QVTimperative;
@@ -39,12 +43,35 @@
public OCL2QVTpCompilerStep(@NonNull CompilerChain compilerChain, @NonNull QVTimperative qvti,
@Nullable Map<@NonNull String, @Nullable Map<@NonNull Key<Object>, @Nullable Object>> options,
- @NonNull URI oclDocURI, URI... extendedDocURIs) {
+ @NonNull URI oclDocURI, @NonNull URI... extendedDocURIs) throws CompilerChainException {
super(compilerChain, QVTP_STEP);
this.traceabilityPropName = getTraceabilityPropertyName();
- this.oclASUri = ClassUtil.nonNullState(qvti.parse(oclDocURI)).getURI();
- for (URI oclDocUri : extendedDocURIs) {
- this.extendedASUris.add(ClassUtil.nonNullState(qvti.parse(oclDocUri)).getURI()); // We add the AS URI
+ ResourceSet externalResourceSet = qvti.getResourceSet();
+ CSResource csResource = (CSResource) externalResourceSet.getResource(oclDocURI, true);
+ if (csResource == null) {
+ throw new CompilerChainException("Failed to parse " + oclDocURI);
+ }
+ ASResource asResource = qvti.cs2as(csResource);
+ this.oclASUri = ClassUtil.nonNullState(asResource.getURI());
+ for (@NonNull URI extendedDocURI : extendedDocURIs) {
+ csResource = (CSResource) externalResourceSet.getResource(extendedDocURI, true);
+ if (csResource == null) {
+ throw new CompilerChainException("Failed to parse " + extendedDocURI);
+ }
+ asResource = qvti.cs2as(csResource);
+ this.extendedASUris.add(ClassUtil.nonNullState(asResource.getURI())); // We add the AS URI
+ }
+ StringBuilder s = null;
+ for (@NonNull Resource resource : externalResourceSet.getResources()) {
+ if (resource.getErrors().size() > 0) {
+ if (s == null) {
+ s = new StringBuilder();
+ }
+ s.append(PivotUtil.formatResourceDiagnostics(resource.getErrors(), "\nErrors in " + resource.getURI(), "\n\t"));
+ }
+ }
+ if (s != null) {
+ throw new CompilerChainException(s.toString());
}
}
@@ -90,9 +117,10 @@
* @param options optional options
* @param oclDocURI the mandatory main OCL document URI to compile
* @param extendedDocURIs optional OCL document URIs that the main one extends
+ * @throws CompilerChainException
*/
public OCL2QVTiCompilerChain(@NonNull QVTimperative qvti, @Nullable Map<@NonNull String, @Nullable Map<@NonNull Key<Object>, @Nullable Object>> options,
- @NonNull URI oclDocURI, URI... extendedDocURIs) {
+ @NonNull URI oclDocURI, @NonNull URI... extendedDocURIs) throws CompilerChainException {
super(qvti.getEnvironmentFactory(), oclDocURI, options);
this.ocl2qvtpCompilerStep = new OCL2QVTpCompilerStep(this, qvti, options, oclDocURI, extendedDocURIs);
}