Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Willink2017-03-07 12:04:10 +0000
committerEd Willink2017-03-11 10:47:44 +0000
commitdd289b130ce0174a7cd6852612c8c77f923c14de (patch)
treef1fa9d243794a8eed1c78abef27fe07fee207e88
parent33dff1ff350aa3aeecc56e75e4fc862ab4600e7a (diff)
downloadorg.eclipse.qvtd-dd289b130ce0174a7cd6852612c8c77f923c14de.tar.gz
org.eclipse.qvtd-dd289b130ce0174a7cd6852612c8c77f923c14de.tar.xz
org.eclipse.qvtd-dd289b130ce0174a7cd6852612c8c77f923c14de.zip
[unrelated] Add generated debug option
-rw-r--r--plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/QVTiCodeGenOptions.java22
-rw-r--r--plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiCG2JavaVisitor.java35
-rw-r--r--plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/AbstractCompilerChain.java2
-rw-r--r--plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/CompilerChain.java1
-rw-r--r--tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java3
5 files changed, 54 insertions, 9 deletions
diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/QVTiCodeGenOptions.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/QVTiCodeGenOptions.java
index bd2d5f5fa..c991e03ed 100644
--- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/QVTiCodeGenOptions.java
+++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/QVTiCodeGenOptions.java
@@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* E.D.Willink - Initial API and implementation
*******************************************************************************/
@@ -16,27 +16,39 @@ import org.eclipse.ocl.examples.codegen.generator.CodeGenOptions;
public class QVTiCodeGenOptions extends CodeGenOptions
{
/**
+ * True to generate debug code.
+ */
+ private boolean isGeneratedDebug;
+ /**
* True to generate an incremental transformation.
*/
private boolean isIncremental;
-
+
/**
* Optional packaging prefix (may have internal dots, no trailing dots)
*/
private String packagePrefix = null;
-
+
public @Nullable String getPackagePrefix() {
return packagePrefix;
}
+ public boolean isGeneratedDebug() {
+ return isGeneratedDebug;
+ }
+
public boolean isIncremental() {
return isIncremental;
}
-
+
+ public void setIsGeneratedDebug(boolean isGeneratedDebug) {
+ this.isGeneratedDebug = isGeneratedDebug;
+ }
+
public void setIsIncremental(boolean isIncremental) {
this.isIncremental = isIncremental;
}
-
+
public void setPackagePrefix(@Nullable String packagePrefix) {
this.packagePrefix = packagePrefix;
}
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 453267e81..0de0d1fb8 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
@@ -196,6 +196,7 @@ public class QVTiCG2JavaVisitor extends CG2JavaVisitor<@NonNull QVTiCodeGenerato
protected final @NonNull QVTiAnalyzer analyzer;
protected final @NonNull CGPackage cgPackage;
protected final @Nullable Iterable<@NonNull CGValuedElement> sortedGlobals;
+ protected boolean isGeneratedDebug = false;
protected boolean isIncremental = false;
protected boolean alwaysUseClasses = false;
protected boolean useGot = true;
@@ -207,6 +208,7 @@ public class QVTiCG2JavaVisitor extends CG2JavaVisitor<@NonNull QVTiCodeGenerato
this.analyzer = codeGenerator.getAnalyzer();
this.cgPackage = cgPackage;
this.sortedGlobals = sortedGlobals;
+ this.isGeneratedDebug = codeGenerator.getOptions().isGeneratedDebug();
this.isIncremental = codeGenerator.getOptions().isIncremental();
this.alwaysUseClasses = isIncremental;
this.useGot = isIncremental;
@@ -1180,10 +1182,27 @@ public class QVTiCG2JavaVisitor extends CG2JavaVisitor<@NonNull QVTiCodeGenerato
js.append("}\n");
}
- protected void doMappingBody(@NonNull CGMapping cgMapping, boolean hasMappingClass) {
+ protected void doMappingBody(@NonNull CGMapping cgMapping, @Nullable Iterable<@NonNull CGGuardVariable> cgGuardVariables) {
CGValuedElement cgBody = cgMapping.getOwnedBody();
js.append(" {\n");
js.pushIndentation(null);
+ if ((cgGuardVariables != null) && isGeneratedDebug) {
+ js.append("if (debugInvocations) {\n");
+ js.pushIndentation(null);
+ js.appendClassReference(AbstractTransformer.class);
+ js.append(".INVOCATIONS.println(\"invoke " + getMappingName(cgMapping) + "\"");
+ for (@NonNull CGGuardVariable cgGuardVariable : cgGuardVariables) {
+ if (!(cgGuardVariable instanceof ConnectionVariable)) {
+ js.append(" + ");
+ js.append("\", \"");
+ js.append(" + ");
+ js.append(getValueName(cgGuardVariable));
+ }
+ }
+ js.append(");\n");
+ js.popIndentation();
+ js.append("}\n");
+ }
// if (cgBody.isInvalid()) {
// js.append("return handleExecutionFailure(\"" + getMappingName(cgMapping) + "\", ");
// js.appendValueName(cgBody);
@@ -1195,6 +1214,16 @@ public class QVTiCG2JavaVisitor extends CG2JavaVisitor<@NonNull QVTiCodeGenerato
if (!cgBody.isInlined()) {
cgBody.accept(this);
}
+ if ((cgGuardVariables != null) && isGeneratedDebug) {
+ js.append("if (debugInvocations) {\n");
+ js.pushIndentation(null);
+ js.appendClassReference(AbstractTransformer.class);
+ js.append(".INVOCATIONS.println((");
+ js.appendValueName(cgBody);
+ js.append(" ? \"done \" : \"fail \") + \"" + getMappingName(cgMapping) + "\");\n");
+ js.popIndentation();
+ js.append("}\n");
+ }
js.append("return ");
js.appendValueName(cgBody);
js.append(";\n");
@@ -2378,7 +2407,7 @@ public class QVTiCG2JavaVisitor extends CG2JavaVisitor<@NonNull QVTiCodeGenerato
js.append("\n");
js.append("@Override\n");
js.append("public boolean execute() ");
- doMappingBody(cgMapping, true);
+ doMappingBody(cgMapping, null);
if (isIncremental) {
js.append("\n");
doMappingGetBoundValue(cgMapping);
@@ -2401,7 +2430,7 @@ public class QVTiCG2JavaVisitor extends CG2JavaVisitor<@NonNull QVTiCodeGenerato
}
js.append(") ");
- doMappingBody(cgMapping, false);
+ doMappingBody(cgMapping, cgFreeVariables);
}
}
finally {
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/AbstractCompilerChain.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/AbstractCompilerChain.java
index ee71ededa..4572373a2 100644
--- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/AbstractCompilerChain.java
+++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/AbstractCompilerChain.java
@@ -167,6 +167,8 @@ public abstract class AbstractCompilerChain extends CompilerUtil implements Comp
if (javaExtraPrefix != null) {
options.setPackagePrefix(javaExtraPrefix);
}
+ Boolean javaIsGeneratedDebug = compilerChain.getOption(JAVA_STEP, JAVA_GENERATED_DEBUG_KEY);
+ options.setIsGeneratedDebug(javaIsGeneratedDebug == Boolean.TRUE);
Boolean javaIsIncremental = compilerChain.getOption(JAVA_STEP, JAVA_INCREMENTAL_KEY);
options.setIsIncremental(javaIsIncremental == Boolean.TRUE);
String javaCodeSource;
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/CompilerChain.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/CompilerChain.java
index 1a99160e9..aab3c4213 100644
--- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/CompilerChain.java
+++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/CompilerChain.java
@@ -75,6 +75,7 @@ public interface CompilerChain
public static final @NonNull Key<Boolean> VALIDATE_KEY = new Key<>("validate");
public static final @NonNull Key<@Nullable String> JAVA_EXTRA_PREFIX_KEY = new Key<>("javaExtraPrefix");
+ public static final @NonNull Key<@Nullable Boolean> JAVA_GENERATED_DEBUG_KEY = new Key<>("javaGeneratedDebug");
public static final @NonNull Key<@Nullable Boolean> JAVA_INCREMENTAL_KEY = new Key<>("javaIncremental");
public static final @NonNull String GENMODEL_BASE_PREFIX = "genModelBasePrefix";
diff --git a/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java
index 311ca8c26..e57bd08d3 100644
--- a/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java
+++ b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java
@@ -137,6 +137,7 @@ public class QVTrCompilerTests extends LoadTestCase
QVTrCompilerChain.setOption(options, CompilerChain.DEFAULT_STEP, CompilerChain.SAVE_OPTIONS_KEY, TestsXMLUtil.defaultSavingOptions);
QVTrCompilerChain.setOption(options, CompilerChain.JAVA_STEP, CompilerChain.URI_KEY, TESTS_JAVA_SRC_URI);
QVTrCompilerChain.setOption(options, CompilerChain.JAVA_STEP, CompilerChain.JAVA_INCREMENTAL_KEY, isIncremental);
+ QVTrCompilerChain.setOption(options, CompilerChain.JAVA_STEP, CompilerChain.JAVA_GENERATED_DEBUG_KEY, true);
QVTrCompilerChain.setOption(options, CompilerChain.CLASS_STEP, CompilerChain.URI_KEY, TESTS_JAVA_BIN_URI);
QVTrCompilerChain.setOption(options, CompilerChain.GENMODEL_STEP, CompilerChain.GENMODEL_USED_GENPACKAGES_KEY, usedGenPackages);
QVTrCompilerChain.setOption(options, CompilerChain.GENMODEL_STEP, CompilerChain.GENMODEL_OPTIONS_KEY, genModelOptions);
@@ -317,7 +318,7 @@ public class QVTrCompilerTests extends LoadTestCase
Class<? extends Transformer> txClass = myQVT.buildTransformation("forward2reverse",
"Forward2Reverse.qvtr", "reverse",
"http://www.eclipse.org/qvtd/xtext/qvtrelation/tests/forward2reverse/Forward2Reverse", false);//,
- // "FlatStateMachine.FlatStateMachinePackage", "HierarchicalStateMachine.HierarchicalStateMachinePackage");
+ // Class<? extends Transformer> txClass = Forward2Reverse.class;
myQVT.assertRegionCount(BasicMappingRegionImpl.class, 0);
myQVT.assertRegionCount(EarlyMerger.EarlyMergedMappingRegion.class, 0);
myQVT.assertRegionCount(LateConsumerMerger.LateMergedMappingRegion.class, 1);

Back to the top