use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.
the class Environment method isLoopScope.
/**
* Returns true if the given BlockNode is a statement block of a loop statement (for, while, alt)
*/
private static boolean isLoopScope(final BlockNode scope) {
final StatementNode parentSN = scope.getParent();
if (parentSN == null) {
return false;
}
final IVisitableNode scopeSt = parentSN.getAstNode();
return (scopeSt instanceof For_Statement || scopeSt instanceof While_Statement || scopeSt instanceof Alt_Statement);
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.
the class AddImport method run.
@Override
public void run(final IAction action) {
TITANDebugConsole.println("Add import called: ");
if (targetEditor == null || !(targetEditor instanceof TTCN3Editor)) {
return;
}
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
if (file == null) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(FILENOTIDENTIFIABLE);
return;
}
if (!TITANNature.hasTITANNature(file.getProject())) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
return;
}
IPreferencesService prefs = Platform.getPreferencesService();
boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
int offset;
if (!selection.isEmpty() && selection instanceof TextSelection && !"".equals(((TextSelection) selection).getText())) {
if (reportDebugInformation) {
TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
}
TextSelection tSelection = (TextSelection) selection;
offset = tSelection.getOffset() + tSelection.getLength();
} else {
offset = ((TTCN3Editor) targetEditor).getCarretOffset();
}
DeclarationCollector declarationCollector = OpenDeclarationHelper.findVisibleDeclarations(targetEditor, new TTCN3ReferenceParser(false), ((TTCN3Editor) targetEditor).getDocument(), offset, false);
if (declarationCollector == null) {
return;
}
List<DeclarationCollectionHelper> collected = declarationCollector.getCollected();
if (collected.isEmpty()) {
// FIXME add semantic check guard on project level.
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
if (reportDebugInformation) {
TITANDebugConsole.println("No visible elements found");
}
for (String moduleName2 : projectSourceParser.getKnownModuleNames()) {
Module module2 = projectSourceParser.getModuleByName(moduleName2);
if (module2 != null) {
// Visit each file in the project one by
// one instead of
// "module2.getAssignments().addDeclaration(declarationCollector)".
Assignments assignments = module2.getAssignments();
for (int i = 0; i < assignments.getNofAssignments(); i++) {
assignments.getAssignmentByIndex(i).addDeclaration(declarationCollector, 0);
}
}
}
if (declarationCollector.getCollectionSize() == 0) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NOTTTCN3DECLARATION);
return;
}
if (reportDebugInformation) {
TITANDebugConsole.println("Elements were only found in not visible modules");
}
DeclarationCollectionHelper resultToInsert = null;
if (collected.size() == 1) {
resultToInsert = collected.get(0);
} else {
OpenDeclarationLabelProvider labelProvider = new OpenDeclarationLabelProvider();
ElementListSelectionDialog dialog = new ElementListSelectionDialog(null, labelProvider);
dialog.setTitle("Add Import");
dialog.setMessage("Choose element to generate an import statement for.");
dialog.setElements(collected.toArray());
if (dialog.open() == Window.OK) {
if (reportDebugInformation) {
TITANDebugConsole.getConsole().newMessageStream().println("Selected: " + dialog.getFirstResult());
}
resultToInsert = (DeclarationCollectionHelper) dialog.getFirstResult();
}
}
if (resultToInsert == null) {
return;
}
IFile newfile = (IFile) resultToInsert.location.getFile();
Module newModule = projectSourceParser.containedModule(newfile);
if (newModule == null) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage("Could not identify the module in file " + newfile.getName());
return;
}
String ttcnName = newModule.getIdentifier().getTtcnName();
TITANDebugConsole.println("the new module to insert: " + ttcnName);
final IFile actualFile = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
Module actualModule = projectSourceParser.containedModule(actualFile);
int insertionOffset = ((TTCN3Module) actualModule).getAssignmentsScope().getLocation().getOffset() + 1;
MultiTextEdit multiEdit = new MultiTextEdit(insertionOffset, 0);
RewriteSessionEditProcessor processor = new RewriteSessionEditProcessor(((TTCN3Editor) targetEditor).getDocument(), multiEdit, TextEdit.UPDATE_REGIONS | TextEdit.CREATE_UNDO);
multiEdit.addChild(new InsertEdit(insertionOffset, "\nimport from " + ttcnName + " all;\n"));
try {
processor.performEdits();
} catch (BadLocationException e) {
ErrorReporter.logExceptionStackTrace(e);
}
} else {
if (reportDebugInformation) {
for (DeclarationCollectionHelper foundDeclaration : collected) {
TITANDebugConsole.println("declaration:" + foundDeclaration.location.getFile() + ": " + foundDeclaration.location.getOffset() + " - " + foundDeclaration.location.getEndOffset() + " is available");
}
}
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openWarning(null, "Study feature", "Adding a missing importation is still under study");
}
});
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.
the class Export_Debug_AST method run.
@Override
public void run(IAction action) {
if (targetEditor == null)
return;
IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
ProjectSourceParser parser = GlobalParser.getProjectSourceParser(file.getProject());
Module module = parser.containedModule(file);
if (module == null) {
TITANDebugConsole.getConsole().newMessageStream().println("No module was found");
}
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "':");
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
module.accept(new ASTVisitor() {
private int padding = 0;
@Override
public int visit(IVisitableNode node) {
if (node instanceof Assignment) {
Assignment assignment = (Assignment) node;
printInfoln(padding, assignment.getAssignmentName(), assignment.getFullName(), assignment.getLastTimeChecked(), assignment.getLocation());
} else if (node instanceof Identifier) {
printInfoln(padding, "identifier", ((Identifier) node).getDisplayName(), null, ((Identifier) node).getLocation());
} else if (node instanceof Statement) {
Statement statement = (Statement) node;
printInfoln(padding, "statement", statement.getFullName(), statement.getLastTimeChecked(), statement.getLocation());
} else if (node instanceof Reference) {
Reference ref = (Reference) node;
printInfoln(padding, "reference", ref.getFullName(), ref.getLastTimeChecked(), ref.getLocation());
Assignment old = ref.getAssOld();
if (old != null) {
printInfoln(padding + 1, "This reference was last pointing to " + old.getFullName() + " analyzed at " + old.getLastTimeChecked());
}
} else if (node instanceof ComponentTypeBody) {
ComponentTypeBody body = (ComponentTypeBody) node;
Map<String, Definition> map = body.getDefinitionMap();
printInfoln(padding + 1, " contains definitions:");
for (Map.Entry<String, Definition> entry : map.entrySet()) {
printInfoln(padding + 2, entry.getKey() + " was last checked at " + entry.getValue().getLastTimeChecked());
}
}
if (node instanceof StatementBlock || node instanceof Definition) {
padding++;
}
return super.visit(node);
}
@Override
public int leave(IVisitableNode node) {
if (node instanceof StatementBlock || node instanceof Definition) {
padding--;
}
return super.leave(node);
}
});
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "' finished");
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.
the class Port_Utility method getOutgoingType.
/**
* Calculates the type of a template instance when it was to be used as
* a parameter of a send statement.
*
* @param timestamp
* the timestamp of the actual semantic check.
* @param templateInstance
* the template instance whose type needs to be
* calculated.
*
* @return the the type of a template instance when it was to be used as
* a parameter of a sending statement
*/
public static IType getOutgoingType(final CompilationTimeStamp timestamp, final TemplateInstance templateInstance) {
final IType result = templateInstance.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
if (result != null) {
return result.getTypeRefdLast(timestamp);
}
ITTCN3Template template = templateInstance.getTemplateBody();
template = template.setLoweridToReference(timestamp);
return template.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.
the class Port_Utility method getIncomingType.
/**
* Calculates the type of a template instance when it was to be used as
* a parameter of a receiving statement (receive / trigger /
* check-receive).
*
* @param timestamp
* the timestamp of the actual build cycle.
* @param templateInstance
* the template instance whose type needs to be
* calculated.
* @param valueRedirect
* the value redirect of the receiving statement to help
* the identification of the type.
* @param valueRedirectChecked
* after the function executed this will store whether
* the execution has called the checking of value
* redirect. This has to be an array of 1 in length.
*
* @return the the type of a template instance when it was to be used as
* a parameter of a receiving statement
*/
public static IType getIncomingType(final CompilationTimeStamp timestamp, final TemplateInstance templateInstance, final Reference valueRedirect, final boolean[] valueRedirectChecked) {
IType result = templateInstance.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
if (result != null) {
return result;
}
result = checkValueRedirect(timestamp, valueRedirect, null);
valueRedirectChecked[0] = true;
if (result != null) {
return result;
}
final ITTCN3Template template = templateInstance.getTemplateBody();
final ITTCN3Template temp = template.setLoweridToReference(timestamp);
return temp.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
}
Aggregations