summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarsten Thoms2016-02-02 16:30:03 -0500
committerKarsten Thoms2016-02-02 16:32:44 -0500
commitb7ec87274b4db9d5c234fa10d6d5e64f268cd833 (patch)
treeb34b005397eec75583ea1c109e58418a7c2217f5
parent150b45aeb4a32f2a1a648f23203d0b5cd49aab79 (diff)
downloadorg.eclipse.xpand-b7ec87274b4db9d5c234fa10d6d5e64f268cd833.zip
org.eclipse.xpand-b7ec87274b4db9d5c234fa10d6d5e64f268cd833.tar.gz
org.eclipse.xpand-b7ec87274b4db9d5c234fa10d6d5e64f268cd833.tar.xz
[484406] Support for debugger in Xpand files
Change-Id: I85fc593944df22559a200df718ebe9ab74faf7a5 Signed-off-by: Karsten Thoms <karsten.thoms@itemis.de>
-rw-r--r--plugins/org.eclipse.xpand.ui/src/org/eclipse/xpand/ui/debug/XpandPluginAdapter.java151
1 files changed, 106 insertions, 45 deletions
diff --git a/plugins/org.eclipse.xpand.ui/src/org/eclipse/xpand/ui/debug/XpandPluginAdapter.java b/plugins/org.eclipse.xpand.ui/src/org/eclipse/xpand/ui/debug/XpandPluginAdapter.java
index 97d9069..9bbe53c 100644
--- a/plugins/org.eclipse.xpand.ui/src/org/eclipse/xpand/ui/debug/XpandPluginAdapter.java
+++ b/plugins/org.eclipse.xpand.ui/src/org/eclipse/xpand/ui/debug/XpandPluginAdapter.java
@@ -42,6 +42,7 @@ import org.eclipse.internal.xpand2.model.XpandAdvice;
import org.eclipse.internal.xpand2.model.XpandDefinition;
import org.eclipse.internal.xtend.expression.ast.Expression;
import org.eclipse.internal.xtend.expression.ast.ISyntaxElement;
+import org.eclipse.internal.xtend.expression.ast.SyntaxElement;
import org.eclipse.internal.xtend.expression.debug.EvaluatedElementWrapper;
import org.eclipse.internal.xtend.expression.debug.NoResourceSpecial;
import org.eclipse.swt.graphics.Image;
@@ -55,9 +56,10 @@ import org.eclipse.xtend.ui.debug.ExpressionPluginAdapter;
/**
* The IPluginAdapter implementation for Xpand statements.
- *
+ *
* @author Clemens Kadura (zAJKa)
- * @author Aykut Kilic (itemis) - Bug#465802
+ * @author Karsten Thoms (itemis) - maintenance
+ * @author Aykut Kilic (itemis) - Bug#465802, 484406, 480679
*/
public class XpandPluginAdapter extends ExpressionPluginAdapter {
@@ -78,21 +80,25 @@ public class XpandPluginAdapter extends ExpressionPluginAdapter {
}
@Override
- public boolean canHandleType(String type) {
+ public boolean canHandleType(final String type) {
return TYPE.equals(type);
}
@Override
public String getEditorId() {
- return PluginConfigurationElementUtil.getConfigAttribute("org.eclipse.ui.editors/" + "editor[class=" + XpandEditor.class.getName() + "]/id");
+ return PluginConfigurationElementUtil
+ .getConfigAttribute("org.eclipse.ui.editors/" + "editor[class="
+ + XpandEditor.class.getName() + "]/id");
}
// -------------------------------------------------------------------------
@Override
- protected List<ISyntaxElement> collectFirstLevelElements(IXtendXpandResource res) {
+ protected List<ISyntaxElement> collectFirstLevelElements(
+ final IXtendXpandResource res) {
List<ISyntaxElement> result = new ArrayList<ISyntaxElement>();
- XpandDefinition[] defs = ((Template) res.getExtXptResource()).getDefinitions();
+ XpandDefinition[] defs = ((Template) res.getExtXptResource())
+ .getDefinitions();
for (XpandDefinition def : defs)
result.add(def);
XpandAdvice[] advs = ((Template) res.getExtXptResource()).getAdvices();
@@ -102,7 +108,7 @@ public class XpandPluginAdapter extends ExpressionPluginAdapter {
}
@Override
- protected List<ISyntaxElement> getBody(ISyntaxElement parent) {
+ protected List<ISyntaxElement> getBody(final ISyntaxElement parent) {
List<ISyntaxElement> result = new ArrayList<ISyntaxElement>();
// Definition or Advice
@@ -170,12 +176,12 @@ public class XpandPluginAdapter extends ExpressionPluginAdapter {
result.add(new EvaluatedElementWrapper(parent));
result.addAll(stmt.getParametersAsList());
Expression target = ((ExpandStatement) parent).getTarget();
- if(target != null)
+ if (target != null)
result.add(target);
Expression sep = ((ExpandStatement) parent).getSeparator();
- if(sep != null)
+ if (sep != null)
result.add(sep);
- }
+ }
// ExpressionStmt
else if (parent instanceof ExpressionStatement) {
@@ -184,7 +190,8 @@ public class XpandPluginAdapter extends ExpressionPluginAdapter {
}
else if (parent instanceof Statement)
- XpandLog.logInfo("Implementation error: Wanted to set Breakpoint for unknown statement: " + parent.getClass().getSimpleName());
+ XpandLog.logInfo("Implementation error: Wanted to set Breakpoint for unknown statement: "
+ + parent.getClass().getSimpleName());
else
result.addAll(super.getBody(parent));
return result;
@@ -193,61 +200,114 @@ public class XpandPluginAdapter extends ExpressionPluginAdapter {
@Override
protected ISyntaxElement findElementForPosition(final IResource resource,
final int position, final int line) {
- ISyntaxElement body = super.findElementForPosition(resource, position,line);
- if (body != null)
- return body;
-
ISyntaxElement rootElem = getContainingRootElement(resource, position);
if (rootElem == null)
return null;
- List<ISyntaxElement> bodies = getBody(rootElem); // this is not body but
- // is
- // root element.
- for (ISyntaxElement item : bodies) {
+
+ // this is not body but is root element.
+ ISyntaxElement element = null;
+ List<ISyntaxElement> bodyElements = getBody(rootElem);
+ for (ISyntaxElement item : bodyElements) {
if (contains(item, position)) {
- body = item;
+ element = item;
break;
}
}
- if (body instanceof FileStatement) {
- return getContainingElementOfFileStatement(((FileStatement) body),
- position, line);
- }
+ return getContainingElement((SyntaxElement) element, position);
+ }
+
+ @Override
+ protected ISyntaxElement getContainingElement(final SyntaxElement element,
+ final int position) {
+ if (!contains(element, position))
+ return null;
+
+ if (element instanceof ExpandStatement) {
+ return getContainingElementOfExpandStatement(
+ (ExpandStatement) element, position);
+ } else if (element instanceof ExpressionStatement) {
+ return getContainingElementOfExpressionStatement(
+ (ExpressionStatement) element, position);
+ } else if (element instanceof FileStatement)
+ return getContainingElementOfFileStatement((FileStatement) element,
+ position);
+ else if (element instanceof ForEachStatement)
+ return getContainingElementOfForEachStatement(
+ (ForEachStatement) element, position);
+ else if (element instanceof IfStatement)
+ return getContainingElementOfIfStatement((IfStatement) element,
+ position);
+ else if (element instanceof LetStatement)
+ return getContainingElementOfLetStatement((LetStatement) element,
+ position);
+ else if (element instanceof ProtectStatement)
+ return getContainingElementOfProtectStatement(
+ (ProtectStatement) element, position);
+
+ return super.getContainingElement(element, position);
+ }
- return body;
+ private ISyntaxElement getContainingElementOfExpressionStatement(
+ final ExpressionStatement exprStatement, final int position) {
+ return getContainingElement(exprStatement.getExpression(), position);
}
private boolean contains(final ISyntaxElement elem, final int position) {
- return elem.getStart() <= position && elem.getEnd() >= position;
+ return elem.getStart() <= position && elem.getEnd() > position;
+ }
+
+ private ISyntaxElement getContainingElementOfExpandStatement(
+ final ExpandStatement expandStatement, final int position) {
+ List<SyntaxElement> children = new ArrayList<SyntaxElement>();
+ // children.addAll(expandStatement.getParametersAsList());
+ children.add(expandStatement.getTarget());
+ return getContainingChild(expandStatement, children, position);
}
private ISyntaxElement getContainingElementOfFileStatement(
- final FileStatement fileStatement, final int position,
- final int line) {
- for (Statement statement : fileStatement.getBody()) {
- if (statement instanceof ExpressionStatement) {
- ISyntaxElement result = getContainingElementOfExpressionStatement(
- (ExpressionStatement) statement, position, line);
- if (result != null)
- return result;
- }
- }
+ final FileStatement fileStatement, final int position) {
+ List<SyntaxElement> children = new ArrayList<SyntaxElement>();
+ children.add(fileStatement.getTargetFileName());
+ children.addAll(fileStatement.getBodyAsList());
+ return getContainingChild(fileStatement, children, position);
+ }
- return null;
+ private ISyntaxElement getContainingElementOfForEachStatement(
+ final ForEachStatement forStatement, final int position) {
+ List<SyntaxElement> children = new ArrayList<SyntaxElement>();
+ children.add(forStatement.getTarget());
+ children.add(forStatement.getSeparator());
+ children.addAll(forStatement.getBodyAsList());
+ return getContainingChild(forStatement, children, position);
}
- private ISyntaxElement getContainingElementOfExpressionStatement(
- final ExpressionStatement exprStatement, final int position,
- final int line) {
- if (exprStatement.getLine() == line)
- return exprStatement.getExpression();
+ private ISyntaxElement getContainingElementOfIfStatement(
+ final IfStatement ifStatement, final int position) {
+ List<SyntaxElement> children = new ArrayList<SyntaxElement>();
+ children.add(ifStatement.getCondition());
+ children.addAll(ifStatement.getBodyAsList());
+ children.add(ifStatement.getElseIf());
+ return getContainingChild(ifStatement, children, position);
+ }
- return null;
+ private ISyntaxElement getContainingElementOfLetStatement(
+ final LetStatement letStatement, final int position) {
+ List<SyntaxElement> children = new ArrayList<SyntaxElement>();
+ children.add(letStatement.getVarValue());
+ children.addAll(letStatement.getBodyAsList());
+ return getContainingChild(letStatement, children, position);
+ }
+
+ private ISyntaxElement getContainingElementOfProtectStatement(
+ final ProtectStatement protStatement, final int position) {
+ List<SyntaxElement> children = new ArrayList<SyntaxElement>();
+ children.addAll(protStatement.getBodyAsList());
+ return getContainingChild(protStatement, children, position);
}
@Override
- protected boolean isValidReturnElement(ISyntaxElement element) {
+ protected boolean isValidReturnElement(final ISyntaxElement element) {
if (element instanceof TextStatement)
return false;
if (element instanceof Statement)
@@ -266,7 +326,8 @@ public class XpandPluginAdapter extends ExpressionPluginAdapter {
IPath path = new Path("/icons/templatefile.gif");
InputStream is = null;
try {
- is = FileLocator.openStream(XpandEditorPlugin.getDefault().getBundle(), path, false);
+ is = FileLocator.openStream(XpandEditorPlugin.getDefault()
+ .getBundle(), path, false);
} catch (IOException e) {
}
if (is != null) {