use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor in project titan.EclipsePlug-ins by eclipse.
the class SelectionFinder method perform.
void perform() {
// getting the active editor
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editor == null || !(editor instanceof TTCN3Editor)) {
return;
}
final TTCN3Editor targetEditor = (TTCN3Editor) editor;
statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
// getting current selection
final ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
textSelection = extractSelection(selectionService.getSelection());
if (textSelection == null) {
ErrorReporter.logError("No valid statements were found in the selection.");
ExtractToFunctionRefactoring.setStatusLineMsg(ERR_MSG_NO_SELECTION, statusLineManager);
return;
}
// getting selected module
final IResource selectedRes = extractResource(targetEditor);
if (!(selectedRes instanceof IFile)) {
ErrorReporter.logError("ExtractToFunctionRefactoring.findSelection(): Selected resource `" + selectedRes.getName() + "' is not a file.");
return;
}
selectedFile = (IFile) selectedRes;
project = selectedFile.getProject();
sourceParser = GlobalParser.getProjectSourceParser(project);
selectedModule = sourceParser.containedModule(selectedFile);
// iterating through the module for the selected statements
final SelectionVisitor selectionVisitor = new SelectionVisitor(textSelection.getOffset(), textSelection.getLength());
selectedModule.accept(selectionVisitor);
selectedStatements = selectionVisitor.createStatementList(textSelection);
if (selectedStatements.isEmpty()) {
ExtractToFunctionRefactoring.setStatusLineMsg(ERR_MSG_NO_SELECTION, statusLineManager);
return;
}
if (ExtractToFunctionRefactoring.DEBUG_MESSAGES_ON) {
ErrorReporter.logError(selectedStatements.createDebugInfo());
ErrorReporter.logError(createDebugInfo());
}
// finding return type & runs on clause
final RunsOnClauseFinder runsonVisitor = new RunsOnClauseFinder(selectedStatements.getLocation());
selectedModule.accept(runsonVisitor);
runsOnRef = runsonVisitor.getRunsOnRef();
parentFunc = runsonVisitor.getFuncDef();
// finding insert location
if (parentFunc instanceof Definition) {
insertLoc = ((Definition) parentFunc).getLocation().getEndOffset();
} else if (parentFunc instanceof ControlPart) {
final ControlPart cp = (ControlPart) parentFunc;
final Location commentLoc = cp.getCommentLocation();
insertLoc = commentLoc == null ? cp.getLocation().getOffset() : commentLoc.getOffset();
}
//
final ReturnVisitor retVis = new ReturnVisitor();
selectedStatements.accept(retVis);
returnCertainty = retVis.getCertainty();
if (retVis.getCertainty() != ReturnCertainty.NO) {
returnType = runsonVisitor.getReturnType();
}
// checking erroneousness of selection
checkErroneousGoto();
if (containsBreakWithoutLoop()) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_BREAK));
}
if (containsContinueWithoutLoop()) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_CONTINUE));
}
if (retVis.getCertainty() == ReturnCertainty.MAYBE) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_UNCERTAIN_RETURN));
}
}
use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor in project titan.EclipsePlug-ins by eclipse.
the class InsertFieldActionFromEditor method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
// update AST
Utils.updateASTForProjectActiveInEditor("InsertField");
Activator.getDefault().pauseHandlingResourceChanges();
// getting the active editor
final TTCN3Editor targetEditor = Utils.getActiveEditor();
if (targetEditor == null) {
return null;
}
// getting selected file
final IFile selectedFile = Utils.getSelectedFileInEditor("InsertField");
if (selectedFile == null) {
return null;
}
final IStructuredSelection structSelection = new StructuredSelection(selectedFile);
final InsertFieldRefactoring refactoring = new InsertFieldRefactoring(structSelection, null);
// open wizard
final InsertFieldWizard wiz = new InsertFieldWizard(refactoring, refactoring.getSelection());
final RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(wiz);
try {
operation.run(targetEditor.getEditorSite().getShell(), "");
} catch (InterruptedException irex) {
// operation was cancelled
} catch (Exception e) {
ErrorReporter.logError("InsertFieldActionFromEditor: Error while performing refactoring change! ");
ErrorReporter.logExceptionStackTrace(e);
}
// update AST again
Activator.getDefault().resumeHandlingResourceChanges();
final IProject project = selectedFile.getProject();
GlobalParser.getProjectSourceParser(project).reportOutdating(selectedFile);
GlobalParser.getProjectSourceParser(project).analyzeAll();
return null;
}
use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor in project titan.EclipsePlug-ins by eclipse.
the class UngroupModuleparActionFromEditor method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
// update AST
Utils.updateASTForProjectActiveInEditor("UngroupModulepar");
Activator.getDefault().pauseHandlingResourceChanges();
// getting the active editor
final TTCN3Editor targetEditor = Utils.getActiveEditor();
if (targetEditor == null) {
return null;
}
// getting selected file
final IFile selectedFile = Utils.getSelectedFileInEditor("UngroupModulepar");
if (selectedFile == null) {
return null;
}
final IStructuredSelection structSelection = new StructuredSelection(selectedFile);
final UngroupModuleparRefactoring refactoring = new UngroupModuleparRefactoring(structSelection);
// open wizard
final UngroupModuleparWizard wiz = new UngroupModuleparWizard(refactoring);
final RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(wiz);
try {
operation.run(targetEditor.getEditorSite().getShell(), "");
} catch (InterruptedException irex) {
// operation was cancelled
} catch (Exception e) {
ErrorReporter.logError("UngroupModuleparActionFromEditor: Error while performing refactoring change! ");
ErrorReporter.logExceptionStackTrace(e);
}
// update AST again
Activator.getDefault().resumeHandlingResourceChanges();
final IProject project = selectedFile.getProject();
GlobalParser.getProjectSourceParser(project).reportOutdating(selectedFile);
GlobalParser.getProjectSourceParser(project).analyzeAll();
return null;
}
use of org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor in project titan.EclipsePlug-ins by eclipse.
the class OrganizeFromEditor method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editor == null || !(editor instanceof TTCN3Editor || editor instanceof TTCNPPEditor)) {
ErrorReporter.logError("The editor is not found or not a Titan TTCN-3 editor");
return null;
}
final IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
TextFileChange change = null;
try {
change = OrganizeImports.organizeImportsChange(file);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("Error while creating the needed import changes", e);
return null;
}
try {
change.perform(new NullProgressMonitor());
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("Error while performing the needed import changes", e);
}
final IProject project = file.getProject();
GlobalParser.getProjectSourceParser(project).reportOutdating(file);
GlobalParser.getProjectSourceParser(project).analyzeAll();
return null;
}
Aggregations