Skip to content

Commit

Permalink
Improved debugger variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Apr 18, 2024
1 parent d90a4fc commit 16cc38c
Show file tree
Hide file tree
Showing 15 changed files with 663 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
import java.lang.reflect.Type;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.eclipse.acceleo.AcceleoASTNode;
import org.eclipse.acceleo.Block;
import org.eclipse.acceleo.Expression;
import org.eclipse.acceleo.Module;
import org.eclipse.acceleo.OpenModeKind;
Expand All @@ -46,6 +51,7 @@
import org.eclipse.acceleo.debug.AbstractDSLDebugger;
import org.eclipse.acceleo.debug.DSLSource;
import org.eclipse.acceleo.debug.event.IDSLDebugEventProcessor;
import org.eclipse.acceleo.debug.util.FrameVariable;
import org.eclipse.acceleo.debug.util.StackFrame;
import org.eclipse.acceleo.query.AQLUtils;
import org.eclipse.acceleo.query.ast.VariableDeclaration;
Expand Down Expand Up @@ -155,6 +161,16 @@ public void run() {
*/
private final class AcceleoDebugEvaluator extends AcceleoEvaluator {

/**
* The {@link Block} output variable name.
*/
private static final String BLOCK_OUTPUT_VARIABLE = "blockOutput";

/**
* The stack of {@link Block} texts {@link List}.
*/
private Deque<List<String>> blockTextLists = new ArrayDeque<>();

/**
* Constructor.
*
Expand All @@ -167,19 +183,43 @@ private final class AcceleoDebugEvaluator extends AcceleoEvaluator {
super(queryEnvironment.getLookupEngine(), newLine);
}

/**
* Pushes a new {@link Block} text {@link List}.
*/
private void pushBlockTextList() {
blockTextLists.addLast(new ArrayList<>());
}

/**
* Pops the last {@link Block} text {@link List}.
*
* @return the last {@link Block} text {@link List}
*/
private List<String> popBlockTextList() {
return blockTextLists.removeLast();
}

@Override
public Object doSwitch(EObject eObject) {
if (isTerminated()) {
return null;
}
if (eObject instanceof Template || eObject instanceof Query) {
pushStackFrame(Thread.currentThread().getId(), eObject);
} else if (eObject instanceof Block) {
pushBlockTextList();
}
try {
if (isAcceleoInstruction(eObject)) {
final StackFrame currentFrame = peekStackFrame(Thread.currentThread().getId());
currentFrame.setInstruction(eObject);
currentFrame.setVariables(peekVariables());
final LinkedHashMap<String, FrameVariable> variables = new LinkedHashMap<>();
for (Entry<String, Object> entry : peekVariables().entrySet()) {
variables.put(entry.getKey(), getFrameVariable(entry.getKey(), entry.getValue()));
}
currentFrame.setVariables(variables);
currentFrame.getVariables().put(BLOCK_OUTPUT_VARIABLE, getFrameVariable(
BLOCK_OUTPUT_VARIABLE, blockTextLists.peekLast()));
if (!AcceleoDebugger.this.control(Thread.currentThread().getId(), eObject)) {
Thread.currentThread().interrupt();
}
Expand All @@ -188,10 +228,17 @@ public Object doSwitch(EObject eObject) {
} finally {
if (eObject instanceof Template || eObject instanceof Query) {
popStackFrame(Thread.currentThread().getId());
} else if (eObject instanceof Block) {
popBlockTextList();
}
}
}

@Override
protected List<String> createBlockTextsList(Block block) {
return blockTextLists.peekLast();
}

}

/**
Expand Down Expand Up @@ -459,7 +506,8 @@ public EObject getInstruction(String path, long line, long column) {

try {
final IQualifiedNameResolver resolver = queryEnvironment.getLookupEngine().getResolver();
final String moduleQualifiedName = resolver.getQualifiedName(new java.net.URI("file://" + path));
final java.net.URI binaryURI = resolver.getBinaryURI(new java.net.URI("file://" + path));
final String moduleQualifiedName = resolver.getQualifiedName(binaryURI);
if (moduleQualifiedName != null) {
final Object resolved = resolver.resolve(moduleQualifiedName);
if (resolved instanceof Module) {
Expand Down Expand Up @@ -515,7 +563,7 @@ public DSLSource getSource(EObject instruction) {
final AcceleoAstResult moduleAstResult = module.getAst();
final IQualifiedNameResolver resolver = queryEnvironment.getLookupEngine().getResolver();
final String moduleQualifiedName = resolver.getQualifiedName(moduleAstResult.getModule());
java.net.URI moduleSourceURI = resolver.getSourceURI(moduleQualifiedName);
final java.net.URI moduleSourceURI = resolver.getSourceURI(moduleQualifiedName);
path = URIUtil.toFile(moduleSourceURI).toString();

if (instruction instanceof AcceleoASTNode) {
Expand Down Expand Up @@ -610,4 +658,15 @@ protected void printDiagnostic(Diagnostic diagnostic, String indentation) {
}
}

@Override
public FrameVariable getFrameVariable(String name, Object value) {
final FrameVariable res = new FrameVariable();

res.setName(name);
res.setValue(value);
res.setReadOnly(true);

return res;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public String caseNewLineStatement(NewLineStatement newLineStatement) {

@Override
public String caseBlock(Block block) {
final List<String> texts = new ArrayList<>();
final List<String> texts = createBlockTextsList(block);

boolean lastIsEmptyBlock = false;
String lastRemovedIndentation = null;
Expand Down Expand Up @@ -626,6 +626,17 @@ public String caseBlock(Block block) {
return builder.toString();
}

/**
* Creates the {@link List} of {@link String} for the given {@link Block}.
*
* @param block
* the {@link Block}
* @return the created {@link List} of {@link String} for the given {@link Block}
*/
protected List<String> createBlockTextsList(Block block) {
return new ArrayList<>();
}

@Override
public String caseComment(Comment comment) {
return EMPTY_RESULT;
Expand Down
6 changes: 5 additions & 1 deletion plugins/org.eclipse.acceleo.debug.ls/.classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_assignment=0
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=0
Expand Down Expand Up @@ -111,11 +116,12 @@ org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
Expand Down Expand Up @@ -145,6 +151,8 @@ org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=inser
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
Expand All @@ -169,13 +177,17 @@ org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
Expand Down Expand Up @@ -222,6 +234,8 @@ org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do n
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
Expand Down Expand Up @@ -258,9 +272,12 @@ org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not inser
org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert
org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
Expand All @@ -286,6 +303,10 @@ org.eclipse.jdt.core.formatter.tabulation.char=tab
org.eclipse.jdt.core.formatter.tabulation.size=4
org.eclipse.jdt.core.formatter.use_on_off_tags=false
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=false
Loading

0 comments on commit 16cc38c

Please sign in to comment.