Commit f176965e authored by Kristof Szabados's avatar Kristof Szabados
Browse files

this debug action will mark all identifiers that are not in their expected places.


Signed-off-by: Kristof Szabados's avatarKristof Szabados <Kristof.Szabados@ericsson.com>
parent 44929284
......@@ -7,7 +7,7 @@
which accompanies this distribution, and is available at
https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
-->
<?eclipse version="4.4"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.popupMenus">
......@@ -52,13 +52,21 @@
<separator name="organize"/>
</menu>
<action
id="org.eclipse.titan.debug.commands.Export_Debug_AST"
definitionId="org.eclipse.titan.debug.commands.Export_Debug_ASTCommand"
label="Export Debug AST"
icon="icons/titan.gif"
menubarPath="org.eclipse.titan.debug.menu.ContextMenu/organize"
class="org.eclipse.titan.debug.actions.Export_Debug_AST">
</action>
id="org.eclipse.titan.debug.commands.Export_Debug_AST"
definitionId="org.eclipse.titan.debug.commands.Export_Debug_ASTCommand"
label="Export Debug AST"
icon="icons/titan.gif"
menubarPath="org.eclipse.titan.debug.menu.ContextMenu/organize"
class="org.eclipse.titan.debug.actions.Export_Debug_AST">
</action>
<action
id="org.eclipse.titan.debug.commands.Mark_Identifiers"
definitionId="org.eclipse.titan.debug.commands.Mark_IdentifiersCommand"
label="Mark Identifiers"
icon="icons/titan.gif"
menubarPath="org.eclipse.titan.debug.menu.ContextMenu/organize"
class="org.eclipse.titan.debug.actions.Mark_Identifiers">
</action>
<action
id="org.eclipse.titan.debug.commands.ProjectReanalyzer"
definitionId="org.eclipse.titan.debug.commands.ProjectReanalyzer"
......@@ -73,13 +81,20 @@
<editorContribution
id="org.eclipse.titan.designer.editors.ttcn3editor.actions"
targetID="org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor">
<action
id="org.eclipse.titan.debug.actions.Export_Debug_AST"
definitionId="org.eclipse.titan.debug.actions.Export_Debug_AST"
label="Export Debug AST"
icon="icons/titan.gif"
class="org.eclipse.titan.debug.actions.Export_Debug_AST">
</action>
<action
id="org.eclipse.titan.debug.actions.Export_Debug_AST"
definitionId="org.eclipse.titan.debug.actions.Export_Debug_AST"
label="Export Debug AST"
icon="icons/titan.gif"
class="org.eclipse.titan.debug.actions.Export_Debug_AST">
</action>
<action
id="org.eclipse.titan.debug.actions.Mark_Identifiers"
definitionId="org.eclipse.titan.debug.actions.Mark_Identifiers"
label="Mark_Identifiers"
icon="icons/titan.gif"
class="org.eclipse.titan.debug.actions.Mark_Identifiers">
</action>
</editorContribution>
</extension>
<extension
......@@ -94,6 +109,11 @@
name="Export Debug AST"/>
<command
categoryId="org.eclipse.titan.debug.commands.Commands"
description="Mark_Identifiers"
id="org.eclipse.titan.debug.commands.Mark_IdentifiersCommand"
name="Mark Identifiers"/>
<command
categoryId="org.eclipse.titan.debug.commands.Commands"
description="Check a module for code smells"
id="org.eclipse.titan.debug.commands.ProjectReanalyzer"
name="Re-Analyze projects"/>
......@@ -104,13 +124,20 @@
id="org.eclipse.titan.designer.editors.ttcn3editor.actions"
targetID="org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor">
<action
id="org.eclipse.titan.debug.actions.Export_Debug_AST"
definitionId="org.eclipse.titan.debug.commands.Export_Debug_ASTCommand"
label="Export Debug AST"
icon="icons/titan.gif"
class="org.eclipse.titan.debug.actions.Export_Debug_AST">
</action>
<action
id="org.eclipse.titan.debug.actions.Export_Debug_AST"
definitionId="org.eclipse.titan.debug.commands.Export_Debug_ASTCommand"
label="Export Debug AST"
icon="icons/titan.gif"
class="org.eclipse.titan.debug.actions.Export_Debug_AST">
</action>
<action
id="org.eclipse.titan.debug.actions.Mark_Identifiers"
definitionId="org.eclipse.titan.debug.commands.Mark_IdentifiersCommand"
label="Mark Identifiers"
icon="icons/titan.gif"
class="org.eclipse.titan.debug.actions.Mark_Identifiers">
</action>
<action
id="org.eclipse.titan.debug.commands.ProjectReanalyzer"
definitionId="org.eclipse.titan.debug.commands.ProjectReanalyzer"
label="Force Re-Analysis of projects"
......
package org.eclipse.titan.debug.actions;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.titan.designer.AST.ASTVisitor;
import org.eclipse.titan.designer.AST.IVisitableNode;
import org.eclipse.titan.designer.AST.Identifier;
import org.eclipse.titan.designer.AST.Location;
import org.eclipse.titan.designer.AST.Module;
import org.eclipse.titan.designer.consoles.TITANDebugConsole;
import org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor;
import org.eclipse.titan.designer.parsers.GlobalParser;
import org.eclipse.titan.designer.parsers.ProjectSourceParser;
import org.eclipse.ui.IEditorActionDelegate;
import org.eclipse.ui.IEditorPart;
public class Mark_Identifiers implements IEditorActionDelegate {
private TTCN3Editor targetEditor = null;
StringBuilder paddingBuffer = new StringBuilder();
@Override
public void run(final IAction action) {
if (targetEditor == null) {
return;
}
final IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(file.getProject());
final Module module = parser.containedModule(file);
if (module == null) {
TITANDebugConsole.getConsole().newMessageStream().println("No module was found");
}
String content1;
try {
final InputStream is1 = file.getContents();
final char[] buf = new char[1024];
final StringBuilder sb = new StringBuilder();
final InputStreamReader isr = new InputStreamReader(is1);
int len;
while ((len = isr.read(buf)) > 0) {
sb.append(buf, 0, len);
}
content1 = sb.toString();
is1.close();
} catch (Exception e) {
return;
}
final String fileContent = content1;
module.accept(new ASTVisitor() {
@Override
public int visit(final IVisitableNode node) {
if (node instanceof Identifier) {
final Identifier id = (Identifier) node;
final Location loc = id.getLocation();
if (loc.getOffset() == -1) {
return super.visit(node);
}
final String inFile = fileContent.substring(loc.getOffset(), loc.getEndOffset());
final String inEditor = id.getDisplayName();
if (!inEditor.equals(inFile)) {
loc.reportSemanticError("This is an identifier");
}
}
return super.visit(node);
}
});
}
@Override
public void selectionChanged(IAction action, ISelection selection) {
// Nothing to be done
}
@Override
public void setActiveEditor(final IAction action, final IEditorPart targetEditor) {
if (targetEditor instanceof TTCN3Editor) {
this.targetEditor = (TTCN3Editor) targetEditor;
} else {
this.targetEditor = null;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment